asp.net -mvc框架复习(4)-ASP.NET MVC中的约定规则

1.路由规则

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcDemo1
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}

2.ASP.NET MVC中的约定

A..视图访问和寻址规则

1)在控制器中使用View()方法调用视图,返回和“动作方法同名”的视图

2)寻址规则:View()方法默认从“Views文件夹”下寻找和控制器同名的文件夹

B.MVC中的约定

1)控制器:必须以Controller结尾

2)视图必须在Views文件夹下,并且要和控制器同名的子目录中创建

C.约定大于配置

1)提前规定好

2)无需配置

3)不遵守规则出错

原文地址:https://www.cnblogs.com/mhq-martin/p/7912248.html