开发者

MVC wrap content with static content. UserControls?

开发者 https://www.devze.com 2023-03-12 00:08 出处:网络
I\'m trying to wrap content with some static HTML in MVC and I\'m not having any luck figuring this out. There must be an obvious solution that I\'m not seeing, as this would seem like a desired featu

I'm trying to wrap content with some static HTML in MVC and I'm not having any luck figuring this out. There must be an obvious solution that I'm not seeing, as this would seem like a desired feature.

In my View, I need to wrap HTML content with something:

<uc1:mc>
   <p>Hello World!</p>
</uc1:mc>

That will render like:

<div class="ribbon">
   <div class="left"></div>
   <p>Hello World!</p>
   <div class="right"></div>
</div>

With a Template like:

<div class="ribbon">
   <div class="left"></div>
   <%= IncomingMarkupGoesHere %>
   <div class="right"></div>
</div>

The idea is to reuse html that w开发者_如何学编程raps around other html.

I'm currently using two User Controls to achieve this, one with everything before and the other with everything after. Something like this:

<% Html.RenderPartial("RightRibbon_Start"); %>
   Target Content...
<% Html.RenderPartial("RightRibbon_End"); %>

But this seems sloppy and isn't conducive to passing parameters that apply to HTML before and after the target content.

It's important that the content to be wrapped be allow to be written as multiple lined markup and not just a string, otherwise I would just pass the content as the Model.


What about creating helpers and passing the HTML in as an argument?


Passing html markup into an ASP.NET User Control

0

精彩评论

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

关注公众号