What is Views?
  • View is the one of the three components in MVC application. View is responsible for providing the user interface (UI) to the user.
  • In MVC application, all browser requests are mapped to controller and its action method. Controller action method will return the view to the user.
  • All the views are placed inside the ‘Views’ folder with /Views/ [controller name] / [action name] .cshtml format

  • Depending upon the language selection, view files willhavedifferent file type e.g .html, asp, aspx, cshtml, vbhtml
  • Shared folder stores the views which can be shared between controllers
  • In the below code you can see that View() method called inside the action method(Contact) is not mentioned with view name. In this caase action method applies a convention to locate the view which has same name as the action within the /Views/ControllerName directory

  • Action method can call the different view without using the convention

      
    
               
     public ActionResult Contact()
     {
        ViewBag.Message = "Your contact page.";
        return View("NewContact");
     }
    
    
    



  • You can use the tilde syntax to provide the full path to the view
      
    
               
    public ActionResult Contact()
    {
    ViewBag.Message = "Your contact page.";
    return View("~/Views/
           Account/NewContact.cshtml");
    }