I have several ActionResults in my controller. Almost all of them process either AjaxRequest or regular request-dependent requests (duh!). The fact is that if I add something to the database using AjaxRequest, I just want to return OK or ERROR (or 1 or 0, etc.) to my page instead of View () or ParcialView () because I I will process through ajax on the client, and I just need the answer “yes” or “no” (or any other main answer).
If I have a regular request (not ajax), this is normal, because I either redirect to another controller or return a simple view ().
So the question is: what is the best way to return a simple value to my view when processing AjaxRequest () ??
result = Person.Add();
if(Request.IsAjaxRequest()) {
if(result == ok)
return true;
else
return false;
}
else {
if(result == ok)
return Redirect("PersonList");
else
return View("Error:);
}