Adding a View In Mvc 4 razor

Adding a View in mvc 4 razor

Step 1 : Adding a Controller

add a view template that you can use with the Index method. To do this, right-click inside the Index method and click Add View.
The Add View dialog box appears. Leave the defaults the way they are and click the Add button:
The Add View dialog box appears. Leave the defaults the way they are and click the Add button:
Adding a View In Mvc 4 razor
The MVCHelloWorld\Views\Default folder and the MVCHelloWorld\Views\Default\Index.cshtml file are created. You can see them in Solution Explorer
The modified MVCHelloWorld\Views\Default\Index.cshtml file is shown below.

@{
    ViewBag.Title = "Index";
}
<h2>
    Index</h2>
@Html.Raw(ViewBag.Message)
<p>
    MVC 4 razor Example</p>

Run the application and browse to the Default controller (http://localhost:xxxx/Default). The Index method in your controller didn't do much work; it simply ran the statement return View(), which specified that the method should use a view template file to render a response to the browser. Because you didn't explicitly specify the name of the view template file to use, ASP.NET MVC defaulted to using the Index.cshtml view file in the \Views\Default folder.


Adding a View In Mvc 4 razor Adding a View In Mvc 4 razor Reviewed by Bhaumik Patel on 10:24 PM Rating: 5