facebook

Views in MVC

Views in MVC

What are Views?

•The view encapsulates the presentation details of the user's interaction with the app.

•Views are HTML templates with embedded code that generate content to send to the client.

•ViewsuseRazorsyntax,whichallowscodetointeractwithHTMLwithminimalcode.

•ASP.NETCoreMVCviewsare.cshtmlfilesstoredbydefaultinaViewsfolderwithintheapplication.

•Typically,eachcontrollerwillhaveitsownfolder,inwhichareviewsforspecificcontrolleractions.

Benefits of Using Views

 

  • Views provideseparation of concernswithin an MVC app, encapsulating user interface level markup separately from business logic.
  • ASP.NET MVC views useRazor syntaxto make switching between HTML markup and server side logic.
  • Common, repetitive aspects of the app's user interface can easily be reused between views usinglayout and shared directivesorpartial views.

A sample view file

A sample view file (About.cshtml):

Back to Blogs