0
mvc3에서 html 헬퍼를 사용할 때 예외가 발생합니다. 원래 LabelFor 및 TextAreaFor 클래스의 '가상'매개 변수를 사용할 때 예외가 발생했습니다. 내가 가상 키워드를 제거했을 때 잘 작동했습니다.'System.Action'은 1 개의 인수를 사용하지 않습니다. HtmlHelper MVC3
이제 LabelFor 및 RadioBoxForEnum (사용자 지정 도우미)을 추가했습니다. 이러한 것들은 가상이 아닌 열거 형을 사용하며 예외가 다시 발생합니다.
어떤 차이가 있는지 알 수는 없지만 이것을 Telerik 탭에 넣었습니다.
는 예외입니다 :
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>);
을 Heres
도우미에 대한 코드 (내가 SO에 다른 스레드에서이있어)
public static class HtmlExtensions
{
public static MvcHtmlString RadioButtonForEnum<TModel, TProperty>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression
)
{
var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
var names = Enum.GetNames(metaData.ModelType);
var sb = new StringBuilder();
foreach (var name in names)
{
var id = string.Format(
"{0}_{1}_{2}",
htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix,
metaData.PropertyName,
name
);
var radio = htmlHelper.RadioButtonFor(expression, name, new { id = id }).ToHtmlString();
sb.AppendFormat(
"<label for=\"{0}\">{1}</label> {2}",
id,
HttpUtility.HtmlEncode(name),
radio
);
}
return MvcHtmlString.Create(sb.ToString());
}
}
감사 : 여기
CS1593: Delegate 'System.Action' does not take 1 arguments
코드입니다 미리.
J
당신이 RadioBoxForEnum에 대한 코드를 게시 할 수 있을까요? –
@ steve-wilkes OK, 헬퍼 코드를 게시물에 추가했습니다. –