Asp.net mvc 3 ';系统行动';不接受1个参数HtmlHelper MVC3

Asp.net mvc 3 ';系统行动';不接受1个参数HtmlHelper MVC3,asp.net-mvc-3,exception,razor,telerik,html-helper,Asp.net Mvc 3,Exception,Razor,Telerik,Html Helper,在mvc3中使用html帮助程序时出现异常。我最初在使用LabelFor和TextAreaFor与类的“virtual”参数时遇到异常。当我删除虚拟关键字时,效果很好 我现在添加了一个LabelFor和一个RadioBoxForEnum(自定义助手),它们使用一个枚举(不是虚拟的),我再次得到了一个异常 不确定这是否有什么区别,但我已经把它记在了Telerik的账单上 例外情况是: CS1593: Delegate 'System.Action' does not take 1 argument

在mvc3中使用html帮助程序时出现异常。我最初在使用LabelFor和TextAreaFor与类的“virtual”参数时遇到异常。当我删除虚拟关键字时,效果很好

我现在添加了一个LabelFor和一个RadioBoxForEnum(自定义助手),它们使用一个枚举(不是虚拟的),我再次得到了一个异常

不确定这是否有什么区别,但我已经把它记在了Telerik的账单上

例外情况是:

CS1593: Delegate 'System.Action' does not take 1 arguments
代码如下:

items.Add().Text("Categorisation").Content(@<text>
        <div class="TabContent">
            <div class="5050SplitLeft">
                @Html.LabelFor(o => o.ChangeProposalHeader.ChangeProposal.ProgrammeCategory, "Programme:")
                @Html.TextAreaFor(o => o.ChangeProposalHeader.ChangeProposal.ProgrammeCategory
                <br />
                @Html.LabelFor(o => o.ChangeProposalHeader.ChangeProposal.InterfaceCategory, "Interface:")
                @Html.TextAreaFor(o => o.ChangeProposalHeader.ChangeProposal.InterfaceCategory)
                <br />
                @Html.LabelFor(o => o.ChangeProposalHeader.ChangeProposal.TechnicalReadinessCategory, "Technical Readiness Level:")
                @Html.TextAreaFor(o => o.ChangeProposalHeader.ChangeProposal.TechnicalReadinessCategory)
                <br />
                @Html.LabelFor(o => o.ChangeProposalHeader.ChangeProposal.DesignChangeRequirementCategory, "Design Change Requirement Category:")
                @Html.TextAreaFor(o => o.ChangeProposalHeader.ChangeProposal.DesignChangeRequirementCategory)
                <br />
                @Html.LabelFor(o => o.ChangeProposalHeader.ChangeProposal.FitType, "Fit Type:")
                @Html.RadioButtonForEnum(o => o.ChangeProposalHeader.ChangeProposal.FitType)
            </div>
            <div class="5050SplitRight">
            </div>
        </div></text>);
items.Add().Text(“分类”).Content(@
@LabelFor(o=>o.ChangeProposalHeader.ChangeProposal.ProgrammeCategory,“程序:”)
@Html.TextAreaFor(o=>o.ChangeProposalHeader.ChangeProposal.ProgrammeCategory

@LabelFor(o=>o.ChangeProposalHeader.ChangeProposal.InterfaceCegory,“接口:”) @TextAreaFor(o=>o.ChangeProposalHeader.ChangeProposal.InterfaceCategory)
@LabelFor(o=>o.ChangeProposalHeader.ChangeProposal.TechnicalReadinesCategory,“技术准备水平:”) @TextAreaFor(o=>o.ChangeProposalHeader.ChangeProposal.TechnicalReadinesCategory)
@LabelFor(o=>o.ChangeProposalHeader.ChangeProposal.DesignChangeRequirementCategory,“设计变更需求类别:”) @(o=>o.ChangeProposalHeader.ChangeProposal.DesignChangeRequirementCategory)
@LabelFor(o=>o.ChangeProposalHeader.ChangeProposal.FitType,“适合类型:”) @RadioButtonForEnum(o=>o.ChangeProposalHeader.ChangeProposal.FitType) );
这是帮助程序的代码(我是从另一个线程获得的)

public静态类
{
公共静态MvcHtmlString RADIOBUTTONFRENUM(
这个HtmlHelper HtmlHelper,
表情
)
{
var metaData=modelmetada.FromLambdaExpression(表达式,htmlHelper.ViewData);
var names=Enum.GetNames(metaData.ModelType);
var sb=新的StringBuilder();
foreach(名称中的变量名称)
{
var id=string.Format(
"{0}_{1}_{2}",
htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix,
metaData.PropertyName,
名称
);
var radio=htmlhelp.RadioButtonFor(表达式,名称,新的{id=id}).ToHtmlString();
附文格式(
"{1} {2}",
身份证件
HttpUtility.HtmlEncode(名称),
收音机
);
}
返回MvcHtmlString.Create(sb.ToString());
}
}
提前谢谢


J

好的,我认为RadioBoxForEnum代码一定有问题,因为我找到了一种不同的方法,并使用我找到的以下代码创建了一个编辑器模板,这适用于任何问题

Enum_radioButtonList.cshtml

@model Enum

@{
 // Looks for a [Display(Name="Some Name")] or a [Display(Name="Some Name", ResourceType=typeof(ResourceFile)] Attribute on your enum
Func<Enum, string> getDescription = en =>
{
    Type type = en.GetType();
    System.Reflection.MemberInfo[] memInfo = type.GetMember(en.ToString());

    if (memInfo != null && memInfo.Length > 0)
    {

        object[] attrs = memInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute),
                                                        false);

        if (attrs != null && attrs.Length > 0)
            return ((System.ComponentModel.DataAnnotations.DisplayAttribute)attrs[0]).GetName();
    }

    return en.ToString();
};
var listItems = Enum.GetValues(Model.GetType()).OfType<Enum>().Select(e =>
new SelectListItem()
{
    Text = getDescription(e),
    Value = e.ToString(),
    Selected = e.Equals(Model)
});
string prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
int index = 0;
ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;

foreach (var li in listItems)
{
    string fieldName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}_{1}", prefix, index++);
    <div class="editor-radio">
    @Html.RadioButton(prefix, li.Value, li.Selected, new { @id = fieldName }) 
    @Html.Label(fieldName, li.Text)    
    </div>
}
ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
}

你能发布RadioBoxForEnum的代码吗?@steve wilkes好的,我已经在帖子中添加了助手代码。。
@model Enum

@{
 // Looks for a [Display(Name="Some Name")] or a [Display(Name="Some Name", ResourceType=typeof(ResourceFile)] Attribute on your enum
Func<Enum, string> getDescription = en =>
{
    Type type = en.GetType();
    System.Reflection.MemberInfo[] memInfo = type.GetMember(en.ToString());

    if (memInfo != null && memInfo.Length > 0)
    {

        object[] attrs = memInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute),
                                                        false);

        if (attrs != null && attrs.Length > 0)
            return ((System.ComponentModel.DataAnnotations.DisplayAttribute)attrs[0]).GetName();
    }

    return en.ToString();
};
var listItems = Enum.GetValues(Model.GetType()).OfType<Enum>().Select(e =>
new SelectListItem()
{
    Text = getDescription(e),
    Value = e.ToString(),
    Selected = e.Equals(Model)
});
string prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
int index = 0;
ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;

foreach (var li in listItems)
{
    string fieldName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}_{1}", prefix, index++);
    <div class="editor-radio">
    @Html.RadioButton(prefix, li.Value, li.Selected, new { @id = fieldName }) 
    @Html.Label(fieldName, li.Text)    
    </div>
}
ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
}
@Html.EditorFor(o => o.ChangeProposalHeader.ChangeProposal.FitType, "Enum_radioButtonList")