0

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 wraps 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.

Levitikon
  • 7,749
  • 9
  • 56
  • 74
  • I'm looking at a potential solution but I just can't wire it up. The concept of <% using (Html.BeginForm()) %> ... <% } %> is mostly what I need because it wraps HTML with a beginning and ending string, but I can't quite find an example of writing a custom one of these. I say mostly because I'm sure it wraps HTML with strings. I need to wrap html markup with something that will pull from a markup source like a user control. This site almost helps, but the examples pass in string parameters, not markup: http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs – Levitikon Jun 14 '11 at 14:04
  • Found the solution! Refer to: http://stackoverflow.com/questions/6345112/passing-html-markup-into-an-asp-net-user-control – Levitikon Jun 14 '11 at 16:55

2 Answers2

0

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

Rob
  • 1,390
  • 1
  • 12
  • 25
0

Passing html markup into an ASP.NET User Control

Community
  • 1
  • 1
Levitikon
  • 7,749
  • 9
  • 56
  • 74