4

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:

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".

How do I send the parameter "x" and this route convert "x" to "id" parameter name? It's possible?

NOTE: I can't change the action parameters.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but I can't change the parameters, but your response has opened my mind and I'll create a new action only for this route, thanks. I can't believe I did not think of it before, sometimes we seek hard solutions for easy things.
0

Take a look here. You can probably extend it to alias query params.

1 Comment

Thanks @Mrchief, but this is a very ugly solution, but thanks for response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.