asp.net mvc 3 - ViewData is empty when returning view -
i baffled s have never came across this. have shared view called "error" outputs standard message followed custom message:
@model system.web.mvc.handleerrorinfo @{ viewbag.title = "error"; } <h2> sorry, error occurred while processing request. @{ viewdata["errormessage"].tostring(); } </h2>
inside controllers catch block setting viewdata custom message:
catch (exception ex) { ... viewdata["errormessage"] = "this custom message"; return view("error"); }
however, when view loaded, viewdata shows key "errormessage" never outputs string.
your expression not display because don't write out viewdata["errormessage"]
response.
with @{ ... }
create razor code block not write output executes code inside.
to write output need use @
sign:
<h2> sorry, error occurred while processing request. @viewdata["errormessage"] </h2>
more info razor syntax.
Comments
Post a Comment