1、 ControllerDescriptor 的描述

Controller  的Action 方法有以下一些特性:

1.1 ActionNameAttribute特性  他继承自 System.Web.Mvc.ActionNameSelectorAttribute 抽象类

  ActionNameSelectorAttribute  通过 其 抽象方法 IsValidName   判断指定的Action名称是否与目标Action方法相匹配。

   如下代码片段:

添加了 ActionNameAttribute 特性后 访问Action 就会匹配 ActionName 而不是 ActionNames 注意Aciton方法后面多了个“s”

        [ActionName("ActionName")]
public ActionResult ActionNames()
{
return Json("", JsonRequestBehavior.AllowGet);
}

ActionNameSelectorAttribute  与ActionMethodSelectorAttribute 区别: 两者都有Action筛选的作用, 前者是针对Action名称 后者是针对 请求是否匹配

1.2 ActionMethodSelectorAttribute 的类型有7种(:

    HttpGet,HttpPost,HttpPut,HttpDelete,HttpHead,HttpOption,HttpPatch. 如下代码片段:

     [HttpGet]
public ActionResult HttpMethod()
{
return Content("ActionMethodSelectorAttribute ");
}

1.3 AcceptVerbsAttribute 特性, 其与ActionMethodSelectorAttribute 不同之处在 它可以同时匹配多个HTTP方法,如下代码片段:

    这样就可以同时使用POST 或 GET 方式请求, 如果去掉Get  就只能使用Post请求。

   [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
public ActionResult AcceptVerbs()
{
return Json("", JsonRequestBehavior.AllowGet);
}

 1.4 NonActionAttribute 特性:

   设置了 NonActionAttribute 特性的 Action 方法 在请求的时候,该方法总是被排除在候选范围之外,如下代码片段

   当添加了NonActionAttribute特性后 访问就会出现 HTTP 404。 错误

 [NonAction]
public ActionResult NonActions()
{
return Content("NonActionAttribute");
}

2.ActionDescriptor

3.ParameterDescriptor

MVC4 Model ControllerDescriptor的更多相关文章

  1. MVC4 Model View Controller分离成独立项目

    适合人群:了解MVC项目的程序员 开发工具:vs2012 开发语言:C# 小项目或功能比较单一的项目可以直接新建一个MVC基本项目类型即可,但随着需求不断迭代,项目的功能模块越来越多,甚至有些模块可以 ...

  2. MVC4 Model ValueProvider

    1. NameValueCollectionValueProvider: ValueProvider 的数据容器一般具有类似字典的结构.NameValueCollection 表示一种 key 和va ...

  3. Spring Boot笔记一

    Spring Boot 入门 Spring Boot 简介 > 简化Spring应用开发的一个框架:> 整个Spring技术栈的一个大整合:> J2EE开发的一站式解决方案: 微服务 ...

  4. .NET MVC4 数据验证Model(二)

      一.概述 MVC分为ViewModel.Control.View,对数据的封装MVC做的很好,确实是不错的WEB框架,针对MVC的ViewModel封装的也是相当的不错,最近做一个MVC的项目,采 ...

  5. ASP.NET MVC4 传递Model到View

    原文发表在:http://www.star110.com/Note/ReadArticle/60641215331146140043.html 开发环境:.NET MVC4 + EF6.0 模型: 1 ...

  6. EF5&MVC4 学习1、创建新的Contoso University Application,并创建Model Class 生成对应的database

    参考:http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framewo ...

  7. MVC4 中的Model显示设置(含显示Shared/DisplayTemplates和编辑Shared/EditorTemplates)

    转载于: MVC4 中的Model显示设置(含显示Shared/DisplayTemplates和编辑Shared/EditorTemplates) 虽然 [Display(Name="XX ...

  8. [转]ASP.NET MVC4中@model使用多个类型实例的方法

    本文转自:http://blog.csdn.net/hulihui/article/details/48199897 有时需要在ASP.NET MVC4的视图的@model中使用多个类型的实例,.NE ...

  9. 【MVC版本】MVC3、MVC4之MODEL验证大比拼

    1.密码验证 MVC3 [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = &quo ...

随机推荐

  1. scrapy框架的日志等级和请求参数

    一 . Scrapy的日志等级 - 在使用 scrapy crawl xxx 允许程序时,在终端里打印输出的就是scrapy的日志信息 - 日志信息的种类 : ERROR : 错误信息 WARNING ...

  2. Python if判断语句

    a=input('输入你的用户名:') if a == "lilei": print('李磊,等你好久了') elif a == "wanghui": prin ...

  3. Struts2 配置Action详解

     Struts2的核心功能是action,对于开发人员来说,使用Struts2主要就是编写action,action类通常都要实现com.opensymphony.xwork2.Action接口,并实 ...

  4. codeforce 1070 E Getting Deals Done(二分求最大化最小值)

    Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a tas ...

  5. /etc/rc5.d/s991local: line25: eject:command not found错误

      使用虚拟机安装centos出现错误,原因是我使用的镜像是最小级别的,没有图形化界面,只有终端窗口 有人用vmware安装minimal centos报错/etc/rc5.d/s99local : ...

  6. 将DataTable中的数据导出成Excel

    public bool ExportFile(System.Data.DataTable dt){    SaveFileDialog sfd = new SaveFileDialog();    s ...

  7. Dell 1420N使用Kubuntu默认无线驱动后网络不稳定的解决方法

    前几天在我的Dell 1420N上安装了Kubuntu 13.04,装了系统软件中的私有无线网卡驱动Broadcom STA wireless driver后,虽然能上网,但是很不稳定,经常断线,非常 ...

  8. 275. H-Index II 递增排序后的论文引用量

    [抄题]: Given an array of citations in ascending order (each citation is a non-negative integer) of a ...

  9. 276. Paint Fence篱笆涂色

    [抄题]: There is a fence with n posts, each post can be painted with one of the k colors. You have to ...

  10. zabbix自动发现监控mysql

    一. 数据库给只读权限 1.1 grant usage on *.* to 'zabbix'@'127.0.0.1' identified by 'zabbix'; flush privileges; ...