View In Asp.Net MVC By Sagar Jaybhay

In this article you will able to understand what is View In Asp.Net MVC. How to Create View In MVC By Sagar Jaybhay









Views In Asp.Net MVC









The purpose of view in MVC to render the data in the format that the end-user want. If you want to return the view from the action method which you going to create by default MVC adds the same name to view as an action method name See below image.









View In Asp.Net MVC
View In Asp.Net MVC








Our application, we add a NameList method and by using the MVC dialog box we are going to add View. The name of the method and view name is the same is MVC default convention and this view is added Under the Views -> Home(Controller Name Folder)-> View See below image.









Create View In Asp.Net MVC
Create View In Asp.Net MVC








public ActionResult NameList()

var list=new List<string>()

"Sagar Jaybhay",
"Ram",
"Raghu",
"Ravan"

;
ViewBag.list = list;
return View();










https://youtu.be/NQrOa3cWPOw








Above is Controller action method and below is the code for view.









@
ViewBag.Title = "NameList";


<h2>NameList</h2>

<h3>List Of Names</h3>

<br/>

<div class="row">
<ul>
@foreach (var str in ViewBag.list)

<li>@str</li>

</ul>
</div>








See the below image which is our output.









OutPut View In Asp.Net MVC
OutPut View In Asp.Net MVC








Also, one more important note in View if you want to switch between Html code and C# code you need to use @( at the rate) symbol. In the above example, we use ViewBag to pass data from controller to view. In the coming up tutorial I will explain in detail about ViewBag and ViewData which is a mechanism to pass data from controller to View.









GitHub – https://github.com/Sagar-Jaybhay/MVC5

Comments

Popular posts from this blog

How to Start a YouTube Channel Free - Complete Guide

How Angular know which module is the startup module?

How to Start a YouTube Channel Free - Complete Guide