在剃须刀视图上缺少@using

时间:2014-07-22 14:12:56

标签: c# asp.net-mvc asp.net-mvc-4 razor

在我的_Layout.cshtml中我有这个HTML代码

@using PreVenta
<li class="@Html.ActivePage("Home")">
    <a href="@Url.Action("Index", "Home")">
        <i class="fa fa-home"></i>
        <span class="title">Home</span>
        <span class="@Html.SelectedPage("Home")" /> 
    </a>
</li>

我有一个帮手来检测当前的活动页面

public static string ActivePage(this HtmlHelper helper, string controller)//, string action)
    {
        string classValue = "";

        string currentController = helper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
        //string currentAction = helper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();

        if (currentController.ToLower() == controller.ToLower()) // && currentAction == action)
        {
            classValue = "start active";
        }

        return classValue;
    }

主要问题是当我尝试启动mi webapp时,我收到此错误 编译器错误消息:CS1061:&#39; System.Web.Mvc.HtmlHelper&#39;不包含&#39; ActivePage&#39;的定义没有扩展方法&#39; ActivePage&#39;接受类型&#39; System.Web的第一个参数未找到。 Mvc.HtmlHelper&#39;(您是否缺少using指令或程序集引用?)。

请一些人可以帮助我,因为我非常困惑。谢谢

3 个答案:

答案 0 :(得分:0)

这很奇怪。你能确定你的帮助班看起来像这样吗?

助手类

namespace PreVenta
{
    public static class HtmlHelpers
    {
        public static string ActivePage(this HtmlHelper helper, string controller)
        {
            //your code
        }
    }
}

现在你可以调用如下的帮助方法。

查看

@Html.ActivePage("Home")

答案 1 :(得分:0)

我找到了问题的解决方案......

当visual studio无法成功编译项目时会出现此问题。

修复此问题,我清理了项目,尝试删除dll并重新编译以发布或调试。

坦克到所有人,坦克到VisualTrollStudio):

答案 2 :(得分:-2)

您需要在要使用此帮助程序的视图中添加此命名空间

喜欢

@using AppName.SomeNamespace