I have written following jquery in my partial view:
$.ajax({
type: "POST",
url: '@Url.Action("PostActionName", "ControllerName")',
data: { Id: "01" },
success: function(data)
{
if (data.success="true")
{
window.location = '@Url.Action("GetActionName", "ControllerName")'
}
}
});
The Action name and Controller name are not fixed, they are bound to change depending upon the view wherein this partial view is placed. I have functions to fetch invoking action and controller names, but not sure how I can pass them in @Url.Action.
Following are Javascript functions to fetch action and controller names:
function ControllerName() {
var pathComponents = window.location.pathname.split('/');
var controllerName;
if (pathComponents.length >= 2) {
if (pathComponents[0] != '') {
controllerName = pathComponents[0];
}
else {
controllerName = pathComponents[1];
}
}
return controllerName;
}
function ActionName() {
var pathComponents = window.location.pathname.split('/');
var actionName;
if (pathComponents.length >= 2) {
if (pathComponents[0] != '') {
actionName = pathComponents[1];
}
else {
actionName = pathComponents[2];
}
}
return actionName;
}
Url.Action
. They could well be variables. – Aesthete