MVC View Simple Introduction (internal use)

Source: Internet
Author: User

The previous chapter talked about the controller and returned the string type, but the user interface is often not a simple string to satisfy, so MVC has a view

The responsibility of the view is to provide the user interface to the user,

Below we create a new view

@{    Layout = null;} <! DOCTYPE html>

This view is very simple just to return a text by viewbag

Let's take a look. If you specify a view from the controller

public class Homecontroller:controller    {        ////        GET:/home/public        actionresult Index ()        {            Viewbag.mes = "Hello";            Return View ("Sample");        }    }

This is a simple controller that returns to the sample's view after the MES amplitude and does not require a suffix

We can see that the Controller base class for MVC contains multiple view overloads

        protected internal ViewResult view (IView view);              protected internal ViewResult View (object model);              protected internal ViewResult View (string viewName);              Protected internal Virtual ViewResult view (IView view, object model);              protected internal ViewResult View (string viewName, object model);            protected internal ViewResult View (string viewName, String mastername);        Protected internal virtual ViewResult View (String viewName, String Mastername, object model);

can be accessed according to their actual requirements, in the method above we specified a return view of the sample

If we do not specify how the view controller will match the view, first it will find the same directory home under the index name of the view, if not found will be an error

  

MVC View Simple Introduction (internal use)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.