T4MVC JavaScriptReplacableUrl not working

182 views Asked by At

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?

1

There are 1 answers

1
gius On

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" },
);