传递的HtmlHelper实例与剃刀另一种方法MVC3 [英] Pass HtmlHelper instance to another method MVC3 with Razor

查看:110
本文介绍了传递的HtmlHelper实例与剃刀另一种方法MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经创建了以下两种方法。第一个是对的HtmlHelper扩展方法。第二个被传递辅助的该实例,这让复选框。我实际的例子有无关复选框,这只是说明我的问题最简单的方法。

Ok I have created the following two methods. The first one is an extension method on HtmlHelper. The second one gets passed that instance of the helper and it makes the checkboxes. My actual example has nothing to do with checkboxes, this was just the easiest way to explain my issue.

public static MvcHtmlString MakeBoxGroup(this HtmlHelper<T> Html, List<string> names)
{
    string outStr = "";
    foreach(string name in names)
        outStr += MakeBox(Html, name);

    return new MvcHtmlString(outStr);
}

public static MvcHtmlString MakeBox(HtmlHelper<T> Html, string name)
{
    return Html.CheckBox(name);
}

我的问题:当我尝试这一点告诉我,该HtmlHelper类不执行复选框或任何这些类型的帮手的。任何人都知道如何通过的HtmlHelper的正确实例下来?我假设我只是使用了错误类型在这里,但我不知道。

My Question: When I try this it tells me that the HtmlHelper class doesn't implement CheckBox or any of those types of helpers. Anyone know how to pass the correct instance of the HtmlHelper down? I'm assuming I'm just using the wrong type here, but I'm not sure.

推荐答案

在这里你去.Checkbox是在静态类InputExtensions System.Web.Mvc.Html命名空间。

Here you go .Checkbox are in System.Web.Mvc.Html namespace in static class InputExtensions.

    using System.Web.Mvc.Html;

    public static MvcHtmlString MakeBoxGroup(this HtmlHelper Html, List<string> names)
    {
        string outStr = "";            
        foreach (string name in names)
            outStr += MakeBox(Html, name);

        return new MvcHtmlString(outStr);
    }

    public static MvcHtmlString MakeBox(HtmlHelper Html, string name)
    {
        return Html.CheckBox(name);
         OR
        return InputExtensions.CheckBox(Html,name);           
    }

这篇关于传递的HtmlHelper实例与剃刀另一种方法MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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