First look at the results I want:
It's easy it's a radio button group, when I'm backstage for an HTML object (an instance of HtmlHelper, which is defined in the Webviewpage class under the SYSTEM.WEB.MVC namespace, i.e. it's available for all MVC pages). The above effect can be generated using the following statement:
@Html. Createganderradiobutton ()
Definition of extension method:
Namespace Web.helper
{
Class extendhtml
{
Static mvchtmlstring Createganderradiobutton (thisSystem.Web.Mvc.HtmlHelper html)
{
New StringBuilder ();
Str. Append ("<input type= ' Radio ' value=1 name= ' gander ' > Male");
Str. Append ("<input type= ' Radio ' value=0 name= ' gander ' > Female");
return Mvchtmlstring.create (str. ToString ());
}
}
}
Note that the class in which it resides must be public static, that is, its extension method itself is public static.
For, to use our method directly on the page, or a step, that is, in the Web. config to put the web.helper name
Space Plus, the page can be accessed to:
<namespaces>
namespace="System.Web.Helpers"/>
namespace="SYSTEM.WEB.MVC"/>
namespace="System.Web.Mvc.Ajax"/>
namespace="System.Web.Mvc.Html"/>
namespace="System.Web.Routing"/>
namespace="System.Web.WebPages"/>
namespace="Web.helper"/>
</namespaces>
OK, now an HTML object extension method is done, quickly go to practice a bar!
MVC builds an extension method for HTML objects, using your own controls as easily as you would with a textbox