I searched but could not find any quick solutions for an MVC 3 htmlhelper to create a wrapper method. What I'm looking for is something like:
@html.createLink("caption", "url")
{
<html> content in tags </html>
}
the result should have
<a href="url" title="Caption">
<html> content in tags </html>
</a>
Any help with this.
The way that this is done with BeginForm is that the return type
MvcFormimplimentsIDisposableso that when used within ausingstatement, theDisposemethod ofMvcFormwrites out the closing</form>tag.You can write an extension method that does exactly the same thing.
Here's one I just wrote to demonstrate.
First off, the extension method:
And here's our new type, MvcAnchor:
In your views you can now do:
Which yields the result:
Expanding this slightly to deal with your exact requirement:
and our view:
which yields the result: