I have two controllers Project and Tag, both of which have a create view and get post methods.
From the Project create view I have the option to add a tag which opens a dialog with the tag create view.
When i add the tag it goes to the tag controller create post method at which point i want to be able to get the controller action that sent it there (in this case Project). I have seen the UrlReferer class, is there a better way to get the controller than that?
the reason i need this is i want to be able to do something like
if (Request.IsAjaxRequest())
{
if (REFERER CONTROLLER != Tag Controller)
{
return Json(new { Item = item, Success = true });
}
else
{
return RedirectToAction("Index");
}
}
so basically if the dialog is in another controller then return a json of the new value otherwise return the index action
Edit ended up using this idea again. went for
if (Url.IsLocalUrl(Request.UrlReferrer.AbsoluteUri) && !String.Equals(Request.UrlReferrer.LocalPath.TrimEnd('/'), Url.Action("Index"), StringComparison.OrdinalIgnoreCase))
{
return Json(new { Item = item, Success = true, Field = String.Format("#Selected{0}s", ControllerName) });
}
return Json(new { Success = true, Field = "#mainContent", Url = Url.Action("Index") });
You have a few options:
Options 1 and 2 could be tampered with before your server receives the value.