Rendering Partial View in code MVC Razor

前端 未结 4 1667
攒了一身酷
攒了一身酷 2021-02-12 10:33

I\'m using MVC 3 Razor to make a simple CMS for practice purposes, and the idea is that I\'m creating a few partial views.

I\'m wanting to do a database lookup, and see

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 11:17

    There are two methods that you can use to render a "control".

    @Html.Partial("ViewName")
    @{ Html.RenderPartial("ViewName"); }
    

    You can also render other actions.

    @Html.Action("ActionName", "Controller", new { Values = "yourvalues" })
    @{ Html.RenderAction("ActionName", "Controller", new { Values = "yourvalues" }); }
    

    Notice the second of each one is surrounded by @{ } this is because they do not return a string but render directly to the stream.

提交回复
热议问题