Views:-
In this article we will study about
views in asp.net mvc!
It contains
user interface. Like html , css, JavaScript
, bootstrap as well. In asp.net mvc we prefer Razor view
engine(will discuss in detail) that generates html automatically . Its even
easier than html.
E.g:-Forms etc.
E.g:-Forms etc.
Steps for
adding View:-
- Go to your Method name
- Right click at it
- Select add view by popup box
- Give name as your method name
- Check whether you need layout or not? Check or un-check box
- Click on add view.


You will find
that particular view underneath your controller name folder with in View
folder.
ViewBag:-
It is dynamic container /bag that holds our data and render
it to the view.
Syntax:-
@ViewBag.AnyName.
Razor View Example:-
In Controller:-
public List<string>
listdata = new List<string>()
{
"name","name2","name3"
};
public new ActionResult
View()
{
ViewBag.Data = listdata;
return View(ViewBag.Data);
}
In view:-
@foreach (var
item in ViewBag.Data)
{
<tr>@item</tr>
}
Important Point:-
Always keep same name of view as of
method..
For more checkout videos:-








No comments:
Post a Comment