在MVC 4自定义HTML佣工 [英] Custom html helpers in MVC 4

查看:145
本文介绍了在MVC 4自定义HTML佣工的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的helper类

 命名空间SEM.API.Helpers
{
    公共静态类导航
    {
        公共静态字符串BuildSomething(此的HtmlHelper助手)
        {
            回到空;
        }
    }
}

和添加了命名空间webconfig <添加命名空间=SEM.API.Helpers/>
但我仍然得到一个错误:


  

CS1061:System.Web.Mvc.HtmlHelper


这是不是一个很大的重建后,解决了


解决方案

  

和添加命名空间webconfig <添加命名空间=SEM.API.Helpers/>


请确保你这样做的〜/查看/ web.config中而不是〜/的web.config

试试另一件事情是在 @using 指令添加到您的视图:

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

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

解决方案

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()

这篇关于在MVC 4自定义HTML佣工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆