0

I've added new action to my asp.net mvc application and add specific rule for it inside RouteConfig.cs.

But all parameters passed as 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

3
  • @RahulSingh sorry I can't understand your question. Can you explain more? Commented Feb 24, 2017 at 16:55
  • I mean you don't have placeholder for action like this:- "{controller}/{action}/{platform}/{token}/{uid}" Commented Feb 24, 2017 at 16:56
  • @RahulSingh action is hard coded in my url and defined in route parameters. Commented Feb 24, 2017 at 17:01

1 Answer 1

1

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

where

controller = "Home", 
action = "SendToken", 
id = "platform/token/uid"
Sign up to request clarification or add additional context in comments.

1 Comment

All the problem was that I've missed to pass uid as 3rd parameter and so this route rule was not fired.

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.