Hello everyone I want to know something is there possible. Using ajax send error message if occurred else send view. you can see my code. please help me what should I do. need some suggestions
here is my example
public ActionResult Test()
{
string ErrorText = string.Empty;
if(true)
return View("PagedList");
}
else
{
return Json(new { errorMessage = ErrorText});
}
}
Ajax:-
function Load(page) {
$.ajax({
type: "POST",
url: page,
xhrFields: {
withCredentials: true
},
success: function (data) {
$('#ReportLoad').empty();
$('#ReportLoad').append($.parseHTML(data));
},
error: function (xhr, textStatus, exceptionThrown) {
$('#ReportErrors').empty();
$('#ReportErrors').html(JSON.parse(xhr.responseText));
$('#ReportErrors').show();
},
complete: function () {
}
});
}
I don't know I am doing right way or not Can anyone suggest whats the best way to achieve this.