static void



To build the views during build, edit the project file: <MvcBuildViews>false</MvcBuildViews>

Master Pages (Razor: Layout Pages)

These should live in \Views\Shared\

You can define a site-wide layout in Views/_ViewStart.cshtml (so you don't have to define it per page)
One _ViewStart per area.

ViewData/ViewBag and Models

ViewData (MVC1-2)

ViewData is a name/value dictionary available in the View

Strongly typed views:

ViewBag (MVC3)

ViewBag is a strong-typed wrapper for ViewData (in MVC3+)

@model (MVC3)

In MVC 3 you can have a strong-typed model. Simple models may use the business/data entities directly (or an IEnumerable of them), but you'll probably want a ViewModel specific to the screen (it's also more secure).

@model MvcApplication1.Models.CategoryModel

TempData (MVC2)

The TempDataDictionary (TempData["x"] = "y") is just Session, so can be used with RedirectToAction.

A strong typed model helper like @Html.HiddenFor(x => x.Id) may not use what you expect.
If your controller action has parameters e.g. public ActionResult Edit(int id) then that id is used, not the model.Id!
To fix, do a ModelState.Clear(); in your action.

Partial Views (User controls)

Common partial views should live in \Views\Shared\

You can also use @Html.Action("_HelloWorld" which calls a controller action.

Sections (e.g. for scripts) do not work in partials

Delete-Cancel buttons

A typical CRUD form may have a row of buttons for Save-Cancel-Delete.

$("#Cancel").click(function() {
        window.location = "@Url.Action("Index")";
$('#Delete').click(function() {
    if(confirm("@WebApp.Resources.Crud.AreYouSure")) {
        var form = document.forms[0];
        form.action = "@Url.Action("Delete")";