0

I'm trying to use JavaScriptReplacableUrl to get a url on client side and replace parameters.

My controller method:

virtual ActionResult Details(int id = 0, int acctJobID = 0)

javascript to test JavaScriptReplacableUrl

console.log('@Url.JavaScriptReplaceableUrl(MVC.Distribution.Details())');
//output: /Distribution/Details/0/0 
//expected: /Distribution/Details/{id}/{acctJobID}

This is in T4MVC Version 3.10.0. Is this a bug in T4MVC, or am I missing something?

DLeh
  • 23,806
  • 16
  • 84
  • 128

1 Answers1

0

As stated in T4MVC documentation:

You must define a specific route for JavaScriptReplacableUrl to work like this - it cannot work with 'default routes'. If it cannot find a matching route it behaves like Url.Action().

So, it means you have to add a custom route to make it work:

routes.MapRoute(
    name: "Distribution_Details",
    url: "Distribution/Details/{id}/{acctJobID}",
    defaults: new { controller = "Distribution", action = "Details" },
);
gius
  • 9,289
  • 3
  • 33
  • 62
  • 1
    I feel like this defeats the purpose of trying to get rid of your magic strings. Now you have additional routes to maintain and update if you change or move things around. – Victorio Berra Aug 30 '17 at 17:23