in

Chennai .Net User Group

A platform that enables you to Learn, Share & Grow (India's first .Net user group)

Shiju Varghese's Blog

ASP.NET MVC 3 Beta Support for Code Runs before Views and Strongly Typed Models in Razor Views

Code that Runs Before Views Run

In ASP.NET MVC 3 Beta, we can add a file named _viewstart.cshtml in the views directory  and this will be shared among the all views with in the Views directory. The below code in the _viewstart.cshtml, sets the Layout page for every Views in the Views folder

 

  1. @{
  2.     Layout = "~/Views/Shared/_Layout.cshtml";
  3. }

 

You can put a _viewstart.cshtml file on the any subfolders of Views folder and it will be shared only for that sub folder.

 

Specify Strongly Typed Models in Razor Views

In ASP.NET MVC 3 Beta, we can simply specify the strongly typed model using the following syntax

  1. @model Models.RegisterModel

 

In the above syntax, we have specified RegisterModel in the Models namespace as strongly typed model for our Razor View.

Read the complete post at http://feedproxy.google.com/~r/ShijuVBlog/~3/kcJFQyWobRM/asp-net-mvc-3-beta-support-for-code-runs-before-views-and-strongly-typed-models-in-razor-views.aspx

Only published comments... Oct 07 2010, 12:42 PM by Shiju Varghese's Blog
Copyright © 2002-2008 Chennai .Net User Group. All Rights Reserved. Microsoft and Microsoft logo's are trademarks of Microsoft Corporation