Reputation: 13
I have a Action Method of MVC:
[HttpPost]
public ActionResult callAction(int Id, string ffs, string sid)
{
//Business Logic
return View();
}
and this action is getting called from the JS
var _url = vpath + '/contraller/callAction' + sidpath + '?Id=' + id + '&ffs=' + bfSelected + '&s=' + fps;
clickCount = 1;
$.post(_url, function (data) {
if (data.Completed) {
location.href = data.ReturnUrl;
}
});
Now I want to prevent that action to be called from out side the world. This action should get called from the same application only. I used that [ChildActionOnly]
but its not work
Upvotes: 1
Views: 573
Reputation: 149
Use the ControllerContext.IsChildAction property inside your action to determine if you want to redirect.
For example:
public ActionResult Index()
{
if(!ControllerContext.IsChildAction)
{
//perform redirect here
}
//do stuff here
return View(viewModel);
}
Upvotes: 2