2009-01-21 139 views
1

爲什麼我得到字符串帶下劃線的錯誤「Expected class,interface,enum or struct」?MVC幫助器擴展

public static string IsSelected(this HtmlHelper helper, string A, string B) 

    { 
     return "wtf"; 

    } 

回答

6

你的擴展方法必須是一個靜態類內:

public static class MyExtensions 
{ 
    public static string IsSelected(this HtmlHelper helper, string A, string B) 
    { 
     return "wtf"; 

    } 
} 
+0

該固定一個部件,但它仍然是不註冊與system.web.mvc.htmlhelpers的延伸。還有什麼需要做的? – zsharp 2009-01-21 21:36:13