Reputation: 73
I have a little problem. I use ASP.NET MVC 3 on Visual Web developer express and when i use Html.Raw or Html.Encode in razor view or helper, i get a NullReferenceException à runtime.
for exemple :
@Html.Raw(post.Body)
or other
@Html.Raw(@Html.Encode(comment.Body).Replace(Environment.NewLine, "<br />"))
However, strings are not empty. For exemple, to bypass the first case, i used
@(new HtmlString(post.Body))
But i would understand why it does not work with Html;Raw and Html.Encode, instead try hack.
Thank you in advance for your help.
Upvotes: 2
Views: 1813
Reputation: 73
I solved my problem. I work in a Helper who take as argument an HtmlHelper
@helper Render(System.Web.Mvc.HtmlHelper html, ...
Instead of calling html argument, i called Html object who wasn't instanciate. For resume, instead of
@Html.Raw(...)
I do :
@html.Raw(...)
Thanks for your answers.
Upvotes: 5