ASP.NET MVC 4 笔记

时间:2023-03-08 22:31:44
ASP.NET MVC 4 笔记

1.   MVC2、MV3、MC4 的区别

1)   MVC2

1.   View 文件以*.aspx结尾,为原始html页面内容。

2.   View 代码以<%代码…结束%>。

2)   MVC3

1.   View 文件以*.cshtml结尾,为cshtml页面内容。

2.   View 代码以@开始,例如:@Html.GetType()。

3)   MVC4

1.   View 文件以*.cshtml结尾,为cshtml页面内容(与MVC3略有区别)。

2.   View 代码以@开始,例如:@Html.GetType()。

3.   多了一个App_Start 文件夹和 packages.config 文件。

4.   其中:App_Start 文件夹中包含四个配置文件:

1)   BundleConfig.cs

2)   FilterConfig.cs

3)   RouteConfig.cs

4)   WebApiConfig.cs

2.   Action 可返回类型

1)   View() 法

Ø  描述:创建一个将视图呈现给响应的 System.Web.Mvc.ViewResult 对象。

Ø  重载方法:

protected internal ViewResult View();

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);

2)   Content(string content) 方法

Ø  描述:使用字符串创建一个内容结果对象。

Ø  参数:

content:要写入到响应的内容。

Ø  返回结果:内容结果实例。

3)   RedirectToAction(string actionName, string controllerName) 方法

Ø  描述:使用操作名称和控制器名称重定向到指定的操作。

Ø  参数:

actionName:操作方法的名称。

controllerName:控制器的名称。

Ø  返回结果:重定向结果对象。