C
C#2y ago
Kukuba008

❔ URL generating in MVC

Hello i need help with error that occurs when I'm generating URLs in ASP.NET MVC .NET Framework 4.6.2 application. When URL is generated in 'a' tag using '@Url.Action("Index")?TK=4' it works -> outputs '/folder/controller/index?TK=4'.
<a class="dropdown-item" href="@Url.Action("Index")?TK=4">xxx</a>
<a class="dropdown-item" href="@Url.Action("Index")?TK=4">xxx</a>
But when the URL is passed in parameter to JS function, that does something and then redirects to that URL it will generate the URL wrong -> it generates '/controller/index?TK=4'. It is missing the '/folder/' at the start.
<a class="dropdown-item" href="javascript:DownloadExport('@Url.Action("index")?TK=4');">Excel XLSX</a>
<a class="dropdown-item" href="javascript:DownloadExport('@Url.Action("index")?TK=4');">Excel XLSX</a>
or just starting in the JS function:
$('#View').on('change', function () {
window.location = '@Url.Action("Index")?TK=4';
});
$('#View').on('change', function () {
window.location = '@Url.Action("Index")?TK=4';
});
So: 1) How can I generate it properly in JS ? 2) And what can be wrong with it ? Note: All these pieces of code works well localy and on test (generates the URL with '/folder/'), but it doesn't work on production (doesnt generate '/folder/'), even though there is the same code. So the mistake might be in configuration ?
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server