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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -