Reputation: 1417
I was working in a sample MVC project, i have used the below url action method and its not going to the URL as expected.
I have two views in total- named create and index of person entity. URLs like; app/Person/Create & app/Person/Index.
Here person is controller which is created as class name : PersonController
Now am trying to load Index view back to user, when user clicks on cancel button.
$("#btnCancel").click(function () {
window.location = '@Url.Action("Index", "Person")';
});
and in person controller i have action defined in name Index.
But the url action returns me the url as :- app/person
Also calling this url action hits the breakpoint at the action Index of person coltroller class. And i am expecting the URLs like app/Person/Create & app/Person/Index.
Route config.cs - default one which come is mvc projects:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Can someone help in this issue.?
Upvotes: 0
Views: 871
Reputation: 9927
After compiling the code,
$("#btnCancel").click(function () {
window.location = '@Url.Action("Index", "Person")';
});
becomes like this:
But after compiling the code,
$("#btnCancel").click(function () {
window.location = '@Url.Action("create", "Person")';
});
becomes like this:
Upvotes: 1