時,我有一個擴展方式類似:ASp.NET MVC 3.0錯誤調用通用擴展HTML輔助方法
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);
}
}
}
然後我呼籲Razor視圖這種方法(自動完成該法的工作,它是在視圖)可見,但比我得到的錯誤:
@Html.GetEnumValue<MyEnumHere>(1) //Getting error here
錯誤:Cannot convert method group 'GetEnumValue' to non-delegate type 'object'. Did you intend to invoke the method?
,如果我去這樣的 - 在編譯時沒有錯誤:
Html.GetEnumValue<MyEnumHere>(1) //but in that case didnt get data to display.
在編譯時也沒有得到錯誤,如果去謊言
@{
Html.GetEnumValue<MyEnum>(1); //But then I am getting error during execution
}
錯誤:No overload for method 'Write' takes 0 arguments
有什麼建議?
更新0.1:
得到它這樣的工作:
var value = Html.GetEnumValue<MyEnum>(1);
@value
仍然質疑爲什麼在這種情況下,它不工作:
@Html.GetEnumValue<MyEnumHere>(1)
更新0.2
我更新了我的擴展方法返回IHtmlStirng
仍然沒有得到它後工作:
@using MyTypes.Enumerators
@inherits MvcContrib.FluentHtml.ModelWebViewPage<MyModel>
@foreach (var thing in Model.Stuff)
{
@Html.GetEnumValue<MyEnum>(thing.Id)
}
錯誤執行期間:
「在foreach塊缺少結束‘}’字符。確保你在這個塊中的所有「{」字符都有一個匹配的「}」字符,並且沒有任何「}」字符被解釋爲標記。
<MyEnum>
由於某種原因解釋爲HTML標籤(得到警告:警告1「MyEnum」元素未關閉的所有元件必須是自封閉的或具有匹配的結束標記。),並且還我可以「T導航到在這種情況下我的擴展方法,但如果我從申報(Html.GetEnumValue<MyEnum>(thing.Id)
)刪除@
比我可以瀏覽我的方法
可能你的代碼發佈到您的EnumHelper .GetEnumValue(值); ? –
2011-05-18 10:51:51