Rendering partial views with Razor in MVC5

前端 未结 3 1079
误落风尘
误落风尘 2021-02-12 09:52

I\'m trying to get a partial view to render using Razor in MVC5. When I use

@{ Html.RenderPartial(\"ViewName\", model); }

I get the parser erro

3条回答
  •  清歌不尽
    2021-02-12 10:22

    This is wrong:

    @Html.RenderPartial("ViewName", model);
    

    This is correct:

    @{ Html.RenderPartial("ViewName", model);  }
    

    The parsing error might be caused by the partial view's content. For example, if you have an email address, make sure you use @@ to properly escape the @ sign.

    Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.

提交回复
热议问题