Monday, March 3, 2014

Understanding ASP.NET MVC ??

CSDT IT Solution is a way proud to mention that the Job oriented IT Training is inclusive of platforms that have wider scope in the prevailing and forthcoming IT Job Market. These platforms are picked after a thorough research and analys is based upon the existing and prospective IT industry in mind. CSDT IT Solution provides Software Development Training in the platforms such as PHP & Mysql, .Net & SQL Server 2008/2012 , Software Testing, and Java/J2EE.Csdt It Solution Is Software Development Company in patna bihar(India).Csdt Centre is the first Software Development Training Company in Patna(Bihar).Csdt Centre is best software development training institute/company in Bihar.

In ASP.NET MVC there are three ways - ViewData, ViewBag and TempData to pass data from controller to view and in next request. Like WebForm, you can also use Session to persist data during a user session. Now question is that when to use ViewData, VieBag, TempData and Session. Each of them has its own importance. In this article I am trying to expose the use of these four.

ViewData                                                                     

ViewData is a dictionary object that is derived from ViewDataDictionary class.

ViewData is used to pass data from controller to corresponding view.

It’s life lies only during the current request.

If redirection occurs then it’s value becomes null.

It’s required typecasting for complex data type and check for null values to avoid error.

ViewBag

ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.

Basically it is a wrapper around the ViewData and also used to pass data from controller to corresponding view.

It’s life also lies only during the current request.

If redirection occurs then it’s value becomes null.

It doesn’t required typecasting for complex data type.

TempData

TempData is a dictionary object that is derived from TempDataDictionary class and stored in short lives session.

TempData is used to pass data from current request to subsequent request means incase of redirection.

It’s life is very short and lies only till the target view is fully loaded.

It’s required typecasting for complex data type and check for null values to avoid error.

It is used to store only one time messages like error messages, validation messages.

ViewData, ViewBag and TempData Current Request Example

public class HomeController : Controller
{
public ActionResult Index()
{
var emp = new Employee
{
EmpID=101,
Name = "Deepak",
Salary = 35000,
Address = "Delhi"
};
ViewData["emp"] = emp;
ViewBag.Employee = emp;
TempData["emp"] = emp;
return View(); }
}

@model MyProject.Models.EmpModel;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Welcome to Home Page";
var viewDataEmployee = ViewData["emp"] as Employee; //need typcasting
var tempDataEmployeet = TempData["emp"] as Employee; //need typcasting
}
<h2>Welcome to Home Page</h2>
<div>
<a href="/Employees">
<img src='@Url.Content("\\Content\\Images\\101.jpg")' alt="Best Employee "/>
</a>
<div>
This Year Best Employee is!
<h4>@ViewBag.emp.Name</h4>
<h3>@viewDataEmployee.Name</h3>
<h2>@tempDataEmployee.Name</h2>
</div>

ViewData, ViewBag and TempData Next Request Example

public ActionResult About()
{
var emp = new Employee {
EmpID=101,
Name = "Deepak",
Salary = 35000,
Address = "Delhi"
};
ViewData["emp"] = emp;
ViewBag.Employee = emp;
TempData["emp"] = emp;
//After the redirection, ViewData and ViewBag objects will be null
//Only TempData will exist after redirection
return new RedirectResult(@"~\About\");
}

@model MyProject.Models.EmpModel;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "About";
var tempDataEmployeet = TempData["emp"] as Employee; //need typcasting
}

TempData with Keep method
If you want to keep value in TempData object after request completion, you need to call Keep method with in the current action. There are two overloaded Keep methods to retains value after current request completion.

void Keep()

Calling this method with in the current action ensures that all the items in TempData are not removed at the end of the current request.

@model MyProject.Models.EmpModel;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "About";
var tempDataEmployeet = TempData["emp"] as Employee; //need typcasting
TempData.Keep(); // retains all strings values
}

void Keep(string key)

Calling this method with in the current action ensures that specific item in TempData is not removed at the end of the current request.

@model MyProject.Models.EmpModel;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "About";
var tempDataEmployeet = TempData["emp"] as Employee; //need typcasting
TempData.Keep("emp"); // retains only "emp" string values
}

Key point about TempData and TempData.Keep()

Items in TempData will only tagged for deletion after they have read.

Items in TempData can be untagged by calling TempData.Keep(key).

RedirectResult and RedirectToRouteResult always calls TempData.Keep() to retain items in TempData.

Summary

In this article I try to explain the difference between ViewData, ViewBag and TempData. I hope you will refer this article for your need. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.



 http://csdt.co.in/

Friday, February 28, 2014

Understanding java J2ee

Introduction of J2EE

The J2EE Architecture allows the programmers to divide their work into two major categories Business Logic and Presentation Logic. J2EE Architecture The J2EE Architecture allows the programmers to divide their work into two major categories:

1.Presentation Logic:
Presentation Logic consists of all the program (JSP and Servlets), images and html files that are used to interact with the client. These files are archived into .war file. These files are installed on the web server and these interacts with the users.
2.Business Logic:
These are EJB applications which implements the business logic of the system and are archived into .jar file. Business logic runs on the application server.
These two types of archives are bundled into complete J2EE applications, and delivered as Enterprise Archive (EAR) file.


What is J2EE?

The Java 2 Platform Enterprise Edition (J2EE) technology provides a component-based approach to the design,development,assembly,and deployment of enterprise applications. The J2EE platform provides the ability to reuse components in different applications. J2EE is made up of 13 different technologies including JavaServer Pages,Servlets,Enterprise JavaBeans,JavaMail,XML,JavaMail and many more.


CSDT Patna is leading java Training Center or Institute in Patna, Bihar, India .CSDT provides software training,java 6 months project based training,java 6 weeks summer training programme,java based corporate training,java based training institute, java language training center .CSDT It Solution Provides java based IT Training/Institute/Industrial Training / Live Project Training includes JDBC,SERVLET,JSP(Java Server Page),Struts,Hibernet,Spring and Enterprise beans etc. java/ J2ee 6 Months Project Training for Specially design for MCA\BCA\B.tech Students Project Training , Best java/j2ee training institute ,Best java Training Center in Patna bihar india.



http://csdt.co.in/Java-Training.htm

http://csdt.co.in/Java-Training.htm