I was wondering, is it possible to create your own helper definition, with a using? such as the following which creates a form:
using (Html.BeginForm(params))
{
}
I'd like to make my own helper like that. So a simple example I'd like to do
using(Tablehelper.Begintable(id)
{
<th>content etc<th>
}
which will output in my view
<table>
<th>content etc<th>
</table>
Is this possible? if so, how?
Thanks
Yes it is; however, to use
Tablehelper.*
you would need to subclass the base-view and add aTablehelper
property. Probably easier, though, is to add an extension method toHtmlHelper
:which will allow you to write:
but this will in turn require various other bits of plumbing (to start the element at
BeginTable
, and end it inDispose()
on the returned value).Sure, it's possible:
and then:
will yield:
I'd also recommend you reading about Templated Razor Delegates.