[英]ASP.NET MVC 3 Route parameter problem
I have a desktop system that calls a PHP script (script.php) and I send a parameter called by "x" to this script (ex: script.php?x=123), but now the PHP scripts are being rewritten in ASP.NET/MVC, but I can't change the desktop system, then I've created a route like this: 我有一个调用PHP脚本(script.php)的桌面系统,我将一个名为“x”的参数发送到此脚本(例如:script.php?x = 123),但现在PHP脚本正在重写.NET / MVC,但我无法更改桌面系统,然后我创建了这样的路由:
routes.MapRoute("ScriptPHP",
"myscript/script.php",
new { controller = "MyController", action = "MyAction", x = UrlParameter.Optional }
);
The problem is: MyAction receives a parameter named "id" ( MyAction(int id)
), and this route works only if I call "script.php?id=123". 问题是:MyAction接收一个名为“id”(
MyAction(int id)
)的参数,只有当我调用“script.php?id = 123”时,此路由才有效。
How do I send the parameter "x" and this route convert "x" to "id" parameter name? 如何发送参数“x”并将此路由转换为“x”到“id”参数名称? It's possible?
这是可能的?
NOTE: I can't change the action parameters. 注意:我无法更改操作参数。
You need to change your action method to be the following 您需要将操作方法更改为以下内容
public ActionResult MyAction(int x)
{
}
Once you do that, it'll work as you expect. 一旦你这样做,它会像你期望的那样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.