This project is read-only.


URLs for 'no-area actions' are correct but 'area actions' are missing part of the site root URL


Here's an example of two statements in the same view:
postUrl: '@(Url.JavaScriptReplacableUrl(MVC.Transactions.BatchItems.UpdateAmount()))'
The URLs generated are:

/ProtoSite/help/show-help-text-messages – correct
/Transactions/batch-items/update-amount – incorrect; should be /ProtoSite/Transactions/...

The root URL of the site I'm testing is http://dev-server/ProtoSite
Closed Jan 28, 2015 at 4:10 PM by KevinKuszyk
As part of our move to GitHub, we are closing all the outstanding issues on CodePlex.

If your issue is still valid, please re-open it on GitHub:

Thanks for contributing!


davidebbo wrote Feb 26, 2014 at 10:12 PM

It sounds like you may have a routing issue outside of T4MVC. Please see section 1.1. in the doc and try the isolate without T4MVC.

KennyEvitt wrote Feb 27, 2014 at 4:20 PM

I added the following statements to the same view as in my original description:
console.log('@(Url.Action<BatchItemsController>(c => c.UpdateAmount(0, 0m)))');
console.log('@(Url.Action("UpdateAmount", "BatchItems"))');
console.log('@(Url.Action("UpdateAmount", "BatchItems", new { area = "Transactions" }))');
The output in the console is as follows:


davidebbo wrote Feb 27, 2014 at 5:50 PM

JavascriptReplacableUrl is sort of an odd ball method that doesn't work in all cases, and is not the equivalent of what you are doing in plain MVC (see this discussion).

Are you sure that you mean to use that and not just Url.Action(MVC.Transactions.BatchItems.UpdateAmount())?

You may want to follow up on that thread to reach the contributor who wrote that method (waynebrantley).

KennyEvitt wrote Feb 27, 2014 at 8:15 PM

Aha – you're right that JavaScriptReplacableUrl is sort of an oddball.

I didn't think to use the generated UpdateAmount() method stub, but that works for me. In fact, I didn't realize it existed I until I tried adding the following earlier to my test statements:
console.log('@(Url.Action<BatchItemsController>(c => c.UpdateAmount()))');
I removed it because it threw an error because of the NonAction attribute.

Here are some more statements I tested:


console.log('@(this.Url.Content(String.Concat("~", Url.JavaScriptReplacableUrl(MVC.Transactions.BatchItems.UpdateAmount()))))');
and here is the corresponding console output:


Based on the third statement, the final statement in the JavaScriptReplacableUrl method could be changed to this:
return urlHelper.Content("~/" + specificActionUrl);
Any reason why that wouldn't work or wouldn't be a good idea?