@model for _layout.cshtml on MVC4?

后端 未结 4 1291
眼角桃花
眼角桃花 2021-01-02 09:42

I was wondering if there\'s a way to specify a model for the _layout.cshtml file, i\'ve seen lots of posts with the basic same question with people replying with \"alternati

4条回答
  •  走了就别回头了
    2021-01-02 09:59

    You should delegate the parts of your layout that "need a model" to a separate controller using partial views and RenderAction:

    @Html.RenderAction("SomeAction", "LayoutController")
    

    Have LayoutController.SomeAction return a PartialViewResult, which you can then strongly type to a model.

提交回复
热议问题