Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Extension Method to Produce Open & Closing Tags like Html.BeginForm()
    text
    copied!<p>I wonder if it's possible to create an extension method which has functionality &amp; behaviour similar to Html.BeginForm(), in that it would generate a complete Html tag, and I could specificy its contents inside <code>&lt;% { &amp; } %&gt;</code> tags.</p> <p>For example, I could have a view like:</p> <pre><code>&lt;% using(Html.BeginDiv("divId")) %&gt; &lt;% { %&gt; &lt;!-- Form content goes here --&gt; &lt;% } %&gt; </code></pre> <p>This capability would be very useful in the context of the functionality I'm trying to produce with the example in <a href="https://stackoverflow.com/questions/2412969/using-generics-to-create-htmlhelper-extension-methods">this question</a></p> <p>This would give me the ability to create containers for the types that I'll be </p> <pre><code>&lt;% var myType = new MyType(123, 234); %&gt; &lt;% var tag = new TagBuilder("div"); %&gt; &lt;% using(Html.BeginDiv&lt;MyType&gt;(myType, tag) %&gt; &lt;% { %&gt; &lt;!-- controls used for the configuration of MyType --&gt; &lt;!-- represented in the context of a HTML element, e.g.: --&gt; &lt;div class="MyType" prop1="123" prop2="234"&gt; &lt;!-- add a select here --&gt; &lt;!-- add a radio control here --&gt; &lt;!-- whatever, it represents elements in the context of their type --&gt; &lt;/div&gt; &lt;% } %&gt; </code></pre> <p>I realise this will produce invalid XHTML, but I think there could be other benefits that outweigh this, especially since this project doesn't require that the XHTML validate to the W3C standards.</p> <p>Thanks</p> <p>Dave</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload