I would like to return error html text with “IsError” flag.
How could I implement it?
Here is my trial.
Assuming that I submitted the Ajax.BeginForm and error occured on server side.
Global.asax
void Application_Error(Object sender, EventArgs e)
{
var exception = Server.GetLastError();
var number = GetErrorNumber();
Server.ClearError();
Response.Redirect("/Error?number=" + number, false);
}
View Error/index
<div>
An error occurred<br>
Error number : @ViewBag.ErrorNumber
</div>
ErrorController I want to return JSON including view html and “IsError = true”!!
ViewBag.ErrorNumber = number;
return View();
Client side JavaScript catches the returned value.
And the returned html text would renders if “IsError” was true.(I wish)
I think you should return json and create the HTML DIV on client side using javascript. I think you can not return HTML in json.