Html.RenderPartial giving me strange overload error?

后端 未结 1 1499
难免孤独
难免孤独 2020-12-13 16:55

I made a test partial page named _Test.cshtml and put it in the same directory as my view that will be calling it, here it is:

hi
相关标签:
1条回答
  • 2020-12-13 17:13

    You are getting this error because Html.RenderXXX helpers return void - they have nothing to return because they are writing stuff directly* to response. You should use them like this:

    @{ Html.RenderPartial("_Test"); }
    

    There is also Html.Partial helper, which will work with your syntax, but I'd not recommend using it unless you have to, because of performance (it first composes given partial view into string, and then parent view puts it into response*).

    * this is not entirely true, they are actually being rendered into ViewContext.Writer and once whole page is rendered and composed, the whole thing goes to response

    0 讨论(0)
提交回复
热议问题