私はmvcプロジェクトにいくつかのhtmlextensionsを追加しようとしました。私はそれらを使用しようとすると、彼らはすべてこのHtmlHelper htmlHelperパラメータを期待していますか?しかし、すべての例によると、これらは予想されていません。私は間違って何をしていますか?HtmlExtensions for this HtmlHelper <TModel> htmlHelper
パブリック静的文字列RadioButtonListFor(このHtmlHelperのHtmlHelperの、式>式、文字列tagBase)TModelの:クラス {リターンhtmlHelper.RadioButtonListFor(発現、tagBase、NULL); }
public static string RadioButtonListFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, RadioButtonListViewModel>> expression, String tagBase, object htmlAttributes) where TModel : class
{
return htmlHelper.RadioButtonListFor(expression, tagBase, new RouteValueDictionary(htmlAttributes));
}
public static string RadioButtonListFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, RadioButtonListViewModel>> expression, String tagBase, IDictionary<string, object> htmlAttributes) where TModel : class
{
var inputName = tagBase;
RadioButtonListViewModel radioButtonList = GetValue(htmlHelper, expression);
if (radioButtonList == null)
return String.Empty;
if (radioButtonList.ListItems == null)
return String.Empty;
var containerTag = new TagBuilder("td");
containerTag.MergeAttribute("id", inputName + "_Container");
foreach (var item in radioButtonList.ListItems)
{
var radioButtonTag = RadioButton(htmlHelper, inputName, new SelectListItem { Text = item.Text, Selected = item.Selected, Value = item.Value.ToString() }, htmlAttributes);
containerTag.InnerHtml += radioButtonTag;
}
return containerTag.ToString();
}
これを実行しました。私はメソッド/拡張子にアクセスできます。それは私の見解では、私がそれを使用しようとすると、それは私に最初のパラメータを要求しますが、それはしてはいけません。私は自分自身のインスタンスを渡すように頼んでいます。 –
@billyあなたはビューを投稿できますか? – Eranga
こんにちは、Eranga、それは今働いています。正直に言うとなぜか分からない! –