0

I have just switched from PHP CI(MVC) to ASP.NET MVC4 and also i am new to .net framework. I researched loading multiple views in MVC4 but i always found loading view with multiple Models and such.... What I am trying to do is load multiple view in a single page.

For eg:

I have a view left.cshtml

<div>Hello im on the left section</div>
@RenderBody();

and have next view main.cshtml

<div class="left"> // should come in the left section of the page
    @{Layout = "left.cshtml"}
</div>
<div class="right">
    Contents at the right and many more here
</div>

and from above what i expected is:

// Left section                     Right section

Hello im on the left section |  Contents at the right
                             |  and many more here
                             |
                             |
                             |
                             |

But The result was

Hello im on the left section
Contests at the right and many more here

and the CSS are also very ok. Please help....

2
  • Looks ok, what was the result? Commented Dec 26, 2013 at 12:01
  • @Anarion i updated the result.Please check Commented Dec 26, 2013 at 12:06

2 Answers 2

1

I think you are looking to render partial view. So use

@Html.Partial("ViewName")

OR

@{ Html.RenderPartial("ViewName");  }
Sign up to request clarification or add additional context in comments.

1 Comment

is the left cshtml page?
0

Layout is your main page, it goes "Around" of what is rendered via RenderBody. So, if you want to have your right section always same, and substitute different views to your left section you can create a layout containing "structure" of the page, and then render different views into it. Your code should be:

layout.chtml:

<div class="left"> // should come in the left section of the page
 //Your left.chtml will be substituted here
   @RenderBody();
</div>
<div class="right">
    Contents at the right, they are always the same
</div>

left.chtml

//This line shows which layout you are going to use
@{Layout = "left.cshtml"}
//Whole code below is substitued in plase of "RenderBody" of your layout page
Contents at the left. 

P.S you have to return the left view, not the laout view in your contoller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.