[英]ASP.NET MVC: all controller values are passed null
I've added new action to my asp.net mvc application and add specific rule for it inside RouteConfig.cs
. 我在asp.net mvc应用程序中添加了新操作,并在
RouteConfig.cs
添加了特定规则。
But all parameters passed as null
. 但是所有参数都传递为
null
。
Here is my route rule: 这是我的路线规则:
routes.MapRoute(
"toekn_submit_route",
"{controller}/SendToken/{platform}/{token}/{uid}",
new { controller = "Home", action = "SendToken" }
, new[] { "MvcApplication.Controllers" }
);
And here is action deceleration: 这是动作减速:
public JsonResult SendToken(string platform, string token, string uid) { ... }
I call action using this URL: http://localhost:51650/Home/SendToken/platform/token/uid
我使用以下URL调用操作:
http://localhost:51650/Home/SendToken/platform/token/uid
Order of how routes are added is important. 添加路由的顺序很重要。 First matched route wins.
第一条匹配路线获胜。
Make sure that this added route is added before more general routes otherwise they would be matched by another route that doesn't populate the placeholders as intended. 确保在更通用的路由之前添加此添加的路由,否则它们将与另一个未按预期填充占位符的路由匹配。
routes.MapRoute(
name: "token_submit_route",
url: "{controller}/SendToken/{platform}/{token}/{uid}",
defaults: new { controller = "Home", action = "SendToken" },
namespaces: new[] { "MvcApplication.Controllers" }
);
//...other more general routes.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
For example if the Default
route was placed before the token route it would still match http://localhost:51650/Home/SendToken/platform/token/uid
例如,如果将
Default
路由放置在令牌路由之前,则它仍将与http://localhost:51650/Home/SendToken/platform/token/uid
匹配
where 哪里
controller = "Home",
action = "SendToken",
id = "platform/token/uid"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.