Reputation: 1037
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
Upvotes: 0
Views: 1384
Reputation: 2881
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.
Upvotes: 1
Reputation: 545
Why don't you just use it as a layout page?
@{
Layout = "~/Views/Shared/_Session.cshtml";
}
Upvotes: 0