Views in MVC Application

A view requests information from the model that it uses to generate an output representation to the user.

First Add Home Controller in MVC Project.


ViewBag & ViewData is a mechanism to pass data from controller to view.



To pass data from controller to a view, it's always a good practice to use strongly typed view models.

We use "@" symbol to switch between html and C# code.

ADD VIEW

Enter View Name. and Click Add Button.

ADD VIEW

Now Create Index.cshtml file in View/Home Folder.

Write Following code into Home Controller.

INDEX ACTION

Now open Index.cshtml file. and write  following code.

INDEX VIEW

Now Run Project.(Ctrl+F5)

WELCOME

Post a Comment