.NET MVC5 Introduction (a)

Is like the difference between .NET Framework WebApi and .NET Core WebApi the same, .NET Framework MVC and .NET Core MVC, the difference is between the frame. This first series from the .NET Framework MVC first introduced back again introduce .NET Core MVC

 

 

Narrow MVC:

  MVC is a web development framework

  M: Models, data transfer model, Common entities

  V: View, users can see the view model

  C: Controller, decide which view to users, but also calling logic calculation method which is called Action

Generalized MVC:

  Model、VIew、Controller

  V: Interface

  C: control, connected to M, and V

  M: data and logic

  Design mode programs, one design concept, can effectively separate interface and business.

First, create a FirstController,

public class FirstController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

As well as the return type ViewResultBase, ViewResult, JsonResult, FilePathResult, etc. In fact, these are inherited ActionResult.

WebApi return data, why not have a MVC forget? In fact, whether aspx / ashx / WebApi / MVC, is using Http protocol, so that all requests are achievable.

Aspx: a relatively heavy, there is a default page lifecycle --- front and back end integration, ViewState --- with C / S is one to one

ashx: belong lightweight, no concept of page

MVC: an isolated front and rear ends, C can be specified in any view, you can play back peach polymorphic UI

WebApi: people do prospective specializing in pipeline are independent; RESTFul, there is no concept of action. But in .NET Core, both the pipe and fusion.

Pass by value:

Pass ViewData field value, which is the Object, require conversion. ViewBag, traditional values ​​are dynamic, you can easily access the properties, detect runtime. Both are above will be covered, the latter shall prevail. Model. Traditional values, appropriate data transfer complex, strongly typed. TempData, temporary data, across Action backstage pass, there is a Session which, once it is cleared away.

MasterPage, Layout, default is _layout, you can specify your own.

Global. asax, global style.

public class MvcApplication : System.Web.HttpApplication
{
    private Logger logger = new Logger(typeof(MvcApplication));
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        this.logger.Info("网站启动了。。。");
    }


}

Application_Statr () To execute the global launch, and once, very suitable for initialization can also be static constructor. You can also have a lot else.

dynamic is a dynamic type - runtime detection - whatever you write compile-time
use of commissioned performance than reflection, it can facilitate
a weakly typed language features, easy to do some special treatment

 

Guess you like

Origin www.cnblogs.com/taotaozhuanyong/p/11569839.html