return bool from asp.net mvc actionresult
You could return a json result in form of a bool or with a bool property. Something like this:
[HttpPost]
public ActionResult SetSchedule(FormCollection collection)
{
try
{
// TODO: Add update logic here
return Json(true);
}
catch
{
return Json(false);
}
}
IMHO you should use JsonResult
instead of ActionResult
(for code maintainability).
To handle the response in Jquery side:
$.getJSON(
'/MyDear/Action',
{
MyFormParam: $('MyParamSelector').val(),
AnotherFormParam: $('AnotherParamSelector').val(),
},
function(data) {
if (data) {
// Do this please...
}
});
Hope it helps : )