Using [Display(Name = “X”)] with an enum. Custom HtmlHelper in MVC3 ASP.Net

前端 未结 3 2467
余生分开走
余生分开走 2021-02-20 16:31

Im using a snippet of code from another stackoverflow question:

namespace MvcHtmlHelpers
{
    public static class htmlHelpers
    {
        /// 
         


        
3条回答
  •  长发绾君心
    2021-02-20 17:18

    You probably need an extension method for your enum to get the display attribute that you put on your enum options. Then when you get the name or value of your options enum value in the RadioButtonForEnum method you would just call the extensions method to fill up the value.

    I recently wrote a blog post about this topic: http://joerijans.blogspot.com/2011/10/triple-door-extension-method-custom.html

    Hope this helps.

提交回复
热议问题