c# - Why are extensions not available in @helper? -
i created view extension this:
namespace myproject { public static class pageextensions { public static htmlstring myext(this webviewpage page) {
so can type in razor view:
@this.myext()
please note views include namespace declared via web.config:
<system.web.webpages.razor> <pages pagebasetype="system.web.mvc.webviewpage"> <namespaces> <add namespace="myproject" />
everything good. want write @helper
function , use extension there:
@helper myhelper() { var page = (webviewpage) currentpage; <div> @page.myext() </div> }
but extension not available there. error is:
compiler error message: cs1061: 'system.web.mvc.webviewpage' not contain definition 'myext' , no extension method 'myext' accepting first argument of type 'system.web.mvc.webviewpage' found (are missing using directive or assembly reference?)
what missing?
make sure web.config modified "/views/web.config"
Comments
Post a Comment