Custom html helpers in MVC 4

一个人想着一个人 提交于 2019-11-29 17:06:08

问题


I created the helper class

namespace SEM.API.Helpers
{
    public static class Navigation
    {
        public static string BuildSomething(this HtmlHelper helper)
        {
            return "empty";
        }
    }
}

And added the namespace to webconfig <add namespace="SEM.API.Helpers" /> but I still getting an error:

CS1061: "System.Web.Mvc.HtmlHelper"

It isn't solved after a lot of rebuilds


回答1:


and added namespace to webconfig <add namespace="SEM.API.Helpers" />

Make sure you did this in ~/Views/web.config and not in ~/web.config.

Another thing to try is to add the @using directive to your view:

@using SEM.API.Helpers
@Html.BuildSomething()



回答2:


In addition, you should add to the ~/Areas/[Area name]Views/web.config the same string if Areas used.



来源:https://stackoverflow.com/questions/10998827/custom-html-helpers-in-mvc-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!