asp.net-mvc – ActionExecutingContext – ActionParameters与R
发布时间:2020-12-15 22:39:48 所属栏目:asp.Net 来源:网络整理
导读:给出以下代码: public class MyActionFilter : ActionFilterAttribute{ public override void OnActionExecuting(ActionExecutingContext filterContext) { var a = filterContext.ActionParameters["someKey"]; var b = filterContext.RouteData.Values["s
给出以下代码:
public class MyActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var a = filterContext.ActionParameters["someKey"]; var b = filterContext.RouteData.Values["someKey"]; base.OnActionExecuting(filterContext); } } a和b有什么区别? 我们什么时候应该在路由数据上使用动作参数?有什么不同? 解决方法
当您在OnActionExecuting上使用ActionParameters时,可以更改客户端发送的区域值来处理您的操作,例如:
public class MyActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.ActionParameters["customerId"] = 852; base.OnActionExecuting(filterContext); } } 如果您使用customerId参数执行操作,那么您将获取设置在操作过滤器上的值,因为您的操作具有过滤器,例如: 当您请求这样的URL:/ customer / detail / 123时,您将获得CustomerId上的852值: [MyAction] public ActionResult Detail(int customerId) { // customerId is 852 return View(); } RouteData只是关于URL的值,由路由表进行处理. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – Silverlight 3是否会改变MVC与Silverlight的
- asp-classic – 多个错误如果那么,否则如果
- asp.net-mvc – 将Orchard CMS部署到共享主机的正确方法是什
- asp.net-mvc-3 – ASP.NET MVC 3编辑器模板中的IEnumerable
- asp.net – PreRenderComplete和SaveState之间的时间差
- asp.net-mvc – 添加基于Azure移动应用程序的实时聊天功能
- asp.net – 子对象的MVC模型绑定命名约定?
- asp.net-mvc – 使模型绑定适用于没有默认构造函数的模型
- asp.net – Devexpress网格延迟加载
- asp-classic – 从fso对象创建ado记录集
推荐文章
站长推荐
- asp.net – Windows 10主页:Windows身份验证
- asp.net-mvc – 在MVC中使用ViewBag坏?
- asp.net – 在MVC和WebForms之间共享一个主 – 处
- ASP.NET开发人员试图学习Drupal和PHP
- asp.net-mvc-4 – 发布后保留表单值(不是模型的一
- asp.net – 单个站点上的多个应用程序 – 会话和
- 将变量从ASP.net传递给JavaScript
- 打开排序时出现ASP.NET GridView CSS问题
- ASP.NET网站与ASP.NET WebApp:性能差异是什么?
- asp.net – 在新的MVC4应用程序中获取UserId(int
热点阅读