简体   繁体   中英

MVC- How can I render a page and the controller with @RenderPage (or with something else)?

My situation : I have an Index.cshtml -page and a hidden _Session.cshtml -page. I would like render the _Session.cshtml -page in my Index.cshtml -page.

Problem: If I use the @RenderPage -statement it will render only the page and I get some Null-Exception because the application don't fill my model (I fill the model in the controller).

Hope you can help me

Thank you

you have 2 options to display a partial view:

option1:

@Html.Partial("_Session",model)

option2:

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

You need also to take care where the partial is located, if is located in the same folder with the Index, is ok, otherwise I suggest you to put the partial view in Shared folder.

Why don't you just use it as a layout page?

@{
     Layout = "~/Views/Shared/_Session.cshtml";
 }

@RenderPartial()当然是您要在此处执行的操作?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM