/ , / Views In Asp.Net Mvc

Views In Asp.Net Mvc

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.
Steps for adding View:-
  1.       Go to your Method name
  2.        Right click at it
  3.        Select add view by popup box
  4.        Give name as your method name
  5.        Check whether you need layout or not? Check or un-check box
  6.         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:-

about author

Blogger Sens it website about blogger templates and blogger widgets you can find us on social media
Previous Post :Go to tne previous Post
Next Post:Go to tne Next Post

No comments:

Post a Comment