I have a cshtml file where i declare all my route data.
FileName: _Routes.cshtml
@{ Layout = ""; Context.Response.ContentType = "text/javascript"; }
var commonRoutes = {
userList: '@Url.RouteUrl("Default", new { Controller = "User", Action = "GetUserList" })',
location: '@Url.RouteUrl("Default", new { Controller = "User", Action = "GetUserLocations" })',
}
I also have a Action method in my HomeController
public IActionResult GetRoutes()
{
Response.ContentType = "text/javascript";
return this.View("_Routes");
}
In _Layout.cshtml and _LayoutNone.cshtml, I have to get this commonRoutes as js content since im using this routes in the ajax calls in some of the pages
my current implementation is like:
<script type="text/javascript" src='@Url.RouteUrl("Default", new { Controller = "Home", Action = "GetRoutes"})'></script>
Since I’m migrating my code from MVC to ASP.Net Core (.net8). I’m getting 400 Bad Request error in my network tab.
Need help to fix and understand this issue.