"
 
 
 
ASP.NET (snapshot 2017) Microsoft documentation and samples

How Do I: Create a Custom HTML Helper for an MVC Application?

by Chris Pels

In this video Chris Pels shows how to create a custom HtmlHelper that is not available in the standard set in an MVC application. First, a sample MVC application is created with a demo controller and view to test the custom HtmlHelper. Next, a module is created with a public function that is an extension method which represents the implementation of the custom HtmlHelper. The custom helper is for creating <img> tags in a page and receives several inbound parameters including the id, url, and alt text for the image tag. The logic is then added to the function for returning the completed <img> tag with the specified information. Then the custom HtmlHelper is used on the demo page to display an image. Finally, the custom HtmlHelper is expanded to include multiple constructor overrides which provide flexibility for more easily creating different <img> tags.

▶ Watch video (18 minutes)

Previous Next





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/mvc/videos/mvc-2/how-do-i/how-do-i-create-a-custom-html-helper-for-an-mvc-application.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>