简体   繁体   English

ASP.NET MVC:所有控制器值都传递为null

[英]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.

相关问题 空数据从Angular 5传递到Asp.NET MVC控制器 - Null Data is passed from Angular 5 to Asp.NET MVC Controller 在 ASP.NET Core 中发布到控制器时,所有值都为空 - All values are null when posting to controller in ASP.NET Core Asp.net MVC 将值传递给模态 - Asp.net MVC passed values to modal 在 ASP.Net Core 5 MVC 控制器中,当传递包含小数的 JSON 对象 FromBody 时,模型始终为空 - In ASP.Net Core 5 MVC Controller, when passed a JSON object FromBody that contains a decimal the model is always null ASP.NET CORE,查看 model 的所有字段为 null 时传递回 Z9BBF373797BF7CF7BA62C80023 - ASP.NET CORE, View model has all fields as null when passed back to Controller Asp.Net MVC - Viewmodel 空值 - Asp.Net MVC - Viewmodel null values 动态表单的Asp.NET MVC值已发布但未传递给控制器 - Asp.NET MVC Value of DynamicForm posted but not passed to controller ASP.NET MVC仅将单选按钮输入之一传递给控制器 - ASP.NET MVC Only One of the RadioButton Input is Passed to Controller ASP.NET MVC 2 - Object 传递给删除方法 controller 为空 - ASP.NET MVC 2 - Object passed to delete method controller is empty 控制器从表单 ASP.NET MVC5 接收空值 - Controller receiving null values from a form ASP.NET MVC5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM