In my View
I have a ribbon with a spinner where users select a int
type that I use as parameter to get some data in the repository.
So I made a ajax request:
var url = "/ControllerExample/GetJsonUrl?param=" + s.GetItemValueByName("countParam") ;
jQuery.ajax({
type: "GET",
url: url,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
window.location.href = data;
},
failure: function (errMsg) {
alert(errMsg);
}
});
And in my Controller I have a ActionResult
that returns a JsonResult
with the specific url to the 'success' function:
public ActionResult GetJsonUrl(string param)
{
var urlHelper = new UrlHelper(ControllerContext.HttpContext.Request.RequestContext);
string url = urlHelper.Action("OtherAction", "ControllerExample", new {id = param});
return new JsonResult {Data = url, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
}
So if the result is success, the request goes back to the ajax success function and then go to the ExampleController to execute the OtherAction.
I would like to do it with just one action, is it possible? Refreshing the page in the JsonResult
or something.