Wednesday, November 17, 2010

Passing Data in an ASP.NET MVC Application


Hello Friends,

We will look into how to pass Data from Controller to View in Asp.Net MVC.

Passing Data in an ASP.NET MVC Application

The ASP.NET MVC framework provides page-level containers that can pass data between controllers and views. This topic explains how to pass both weakly typed and strongly typed data in an MVC application. It also explains how to pass temporary state data between action methods.
Passing Data between a Controller and a View
• To render a view, you call the View method of the controller.
• To pass data to the view, you use the ViewData property of the ViewPage class.
If you can pass data from the controller object's ViewData property is passed to the view that has the same name as the action method. Like,
public class HomeController : Controller
{ Add Video
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";

return View();
}
In the view, you can access the ViewData property to obtain data that was passed to the view. The ViewData property is a dictionary that supports an indexer that accepts dictionary keys.

Kindly, find some important links below:

http://msdn.microsoft.com/en-us/library/dd394711.aspx

Also, Asp.Net MVC support for existing ASP.NET features. ASP.NET MVC lets you use features such as forms authentication and Windows authentication, URL authorization, membership and roles, output and data caching, session and profile state management, health monitoring, the configuration system, and the provider architecture.

Also, Asp.Net MVC Supports Web Farm Session Management....
1. By default, the TempDataProvider use Session. You can store the session on database and/or use TEmpDataCookieProvider- based on cookies.
2. MVC does NOT support storing session in URL


Thanks,

Paras Sanghani