开发者

MVC3 renderbody issue

开发者 https://www.devze.com 2023-02-15 20:48 出处:网络
I\'m having a small issue some razor tests, that I\'m doing with RenderBody in MVC3. This is my view: @model List<IAdviceContent>

I'm having a small issue some razor tests, that I'm doing with RenderBody in MVC3.

This is my view:

@model List<IAdviceContent>
@{
    Layout = "~/Views/Shared/Site.cshtml";
}
<div>
@开发者_高级运维{
    foreach (IAdviceContent item in @Model)
    {
       <p>hello</p>
    }
}
</div>

In the master page i just have:

<div id="Container">
   <div id="Header"></div>
   <div class="VerticalBlankSeparator"></div>
   <div id="Content">
   @{
       RenderBody();
    }
   </div>
</div>

The issue I'm having is, that the view is rendered without printing "hello", but the foreach is executed 5 times.

Do you know, what I'm missing in the master or in the view?


Renderbody should not be called as you're calling it as it won't output anything to the stream. Change it to just plain @RenderBody() and it should work just fine.


Try using @RenderBody(); as @RenderBody(). Then it will work fine.


use @RenderBody() instead of :

@{
       RenderBody();
    }

and it will work fine

0

精彩评论

暂无评论...
验证码 换一张
取 消