Is it was possible to test for the existence of a supplied content section when using the RenderSection helper in ASP.NET MVC 3?
For example:
@RenderSection("RightCrumbContentArea", required: false)
If the above isn't supplied, I wish to generate some other content.
Solution 1 There is no difference in the markup between a partial view and a view; the only difference is in how they are delivered to the browser. A partial view is sent via AJAX and must be consumed by JavaScript on the client side, while a View is a full postback. That's it.
RenderBody() renders all the content of the child view which is not wrapped in the named section. RenderSection() renders only a part of the child view which is wrapped under the named section.
RenderBody is required, as it's what renders each view. RenderSection has an optional parameter that lets you mark the section as not required.
You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .
It is possible as far as I know.
Try the following code :
@if (IsSectionDefined("RightCrumbContentArea")) {
@RenderSection("RightCrumbContentArea")
} else {
<span>poo</span>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With