Why is the HtmlHelper instance null in a Razor declarative @helper method?

前端 未结 6 1521
余生分开走
余生分开走 2020-12-15 15:22

Using MVC 3 RTM I\'m getting a strange NullReferenceException:

@helper TestHelperMethod() {
    var extra = \"class=\\\"foo\\\"\";
    
6条回答
  •  盖世英雄少女心
    2020-12-15 16:11

    I know it's not the point but if it is just Html.Raw(value) you were hoping to use when finding this question on Google (as I was) according to the source code of System.Web.Mvc.dll all Html.Raw does is:

    public IHtmlString Raw(string calue)
    {
        return new HtmlString(value);
    }
    

    So I've just used @(new HtmlString(value)) in my helper which works nicely.

提交回复
热议问题