Yannik
Yannik

Reputation: 1037

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

Upvotes: 0

Views: 1384

Answers (3)

Lucian Bumb
Lucian Bumb

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

IntoNET
IntoNET

Reputation: 504

@RenderPartial() is surely what you're trying to do here?

Upvotes: 0

Matthew Alltop
Matthew Alltop

Reputation: 545

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

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

Upvotes: 0

Related Questions