I don’t know what is the error behind the codes below, All I want is to go back to the main page which shows a list of events from the details page of the application when the Cancel button was clicked. Right now when I clicked the Cancel button fromt eh details page, the url is sampleurl:2988/Event/Index instead of sampleurl:2988/Event/330. Any help for this is highly appreciated.
Main Page URL :
sampleurl:2988/Event/330
Details Page:
sampleurl:2988/Event/EditEventDetails/3
Here is the Routes settings.
routes.MapRoute(
"Event", // Route name
"Event/{id}", // URL with parameters
new { controller = "Event", action = "Index", id = 0 } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Event", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Cancel Button use to go back to the main page:
<input type="button" id="btnCancel" url="@Url.Action("Index", "Event", new { id = Model.EM_AID })" value="Cancel" class="button cancelbutton"/>
Jquery Code:
$("#btnCancel").click(function () {
window().location.href = $(this).attr('url');
});
You will need to pass the
id=330which was present in your first page to your details page so that you can correctly generate the return url. Also you could use an ActionLink, no need to use javascript:So here’s the workflow:
/Event/330and clicks on a details link to edit the details of a given event/Event/EditEventDetails/3?IdFromTheFirstPage=330