ASp.NET MVC 3.0 error when calling the universal html extension method

I have an extension method:

namespace System.Web.Mvc.Html
{
    public static class HtmlExtensions
    {
        public static T GetEnumValue<T>(this HtmlHelper helper, int value) where T : struct, IConvertible
        {
            return EnumHelper<T>.GetEnumValue(value);
        }
    }
}

Then I call this method in Razor View ( automatically completed for this method, it is visible on the view ), but I get an error:

@Html.GetEnumValue<MyEnumHere>(1) //Getting error here

error: Cannot convert method group 'GetEnumValue' to non-delegate type 'object'. Did you intend to invoke the method?

If I go like this - no errors at compile time:

Html.GetEnumValue<MyEnumHere>(1) //but in that case didnt get data to display.

Also do not get errors during compilation if go lie, that

 @{
     Html.GetEnumValue<MyEnum>(1); //But then I am getting error during execution  
 }

error: No overload for method 'Write' takes 0 arguments

Any suggestions?

Update 0.1 :

Get it like this:

var value = Html.GetEnumValue<MyEnum>(1);
    @value

still a question why in this case it does not work:

 @Html.GetEnumValue<MyEnumHere>(1)

Update 0.2

after I updated my extension method to return IHtmlStirng, still not got it:

@using MyTypes.Enumerators
@inherits MvcContrib.FluentHtml.ModelWebViewPage<MyModel>

@foreach (var thing in Model.Stuff)
{
    @Html.GetEnumValue<MyEnum>(thing.Id)
}

runtime error :

' foreach "}" . , "}" "{" "}" .

<MyEnum> - html ( : 1 "MyEnum" . , .), , @ (Html.GetEnumValue<MyEnum>(thing.Id)),

+3
1

HTML IHtmlString, ( HTML, ).

, , :

public static IHtmlString GetEnumValue<T>(this HtmlHelper helper, int value) where T : struct, IConvertible
{
    return MvcHtmlString.Create(EnumHelper<T>.GetEnumValue(value).ToString());
}

, , ( , , , < > Razor ):

@(Html.GetEnumValue<MyEnumHere>(1))
+10

All Articles