:こここのデータ型はMVC3 htmlヘルパーメソッドで何ですか?私は、この構文を使用して自分のHTMLヘルパーメソッドを作成しようとしてい
@Html.BootstrapLabelFor(m => Model.Email) //Email is a simple string property.
は、私がこれまで持っているものです。
public static MvcHtmlString BootstrapLabelFor<TModel, TValue>
(this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TValue>> expression)
{
string html = String.Format("<label for='{0}' class='some-class' />",
expression.Email.DisplayName???? - NEED HELP HERE.);
return new MvcHtmlString(html);
}
だから、ここでの要点。
私が知る必要があるのは、式オブジェクト内からDisplayNameプロパティ(呼び出された場合)をフェッチする方法です。それが私が見る必要があると仮定します。ここで
は私のLogOnModelクラスです:
public class LogOnModel
{
[Required(ErrorMessage = "You must enter your email address.")]
[Display(Name = "Email:")]
public string Email { get; set; }
[Required(ErrorMessage = "You must enter your password.")]
[DataType(DataType.Password)]
[Display(Name = "Password:")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
今、私たちはどこかに取得しています。ここに私が今持っているものがあります。私が望むもので正しいプロパティを出力していますが、モデルで使用したDisplayNameメタデータデコレータを使用していません。プロパティ名を吐き出すだけ。助言がありますか?
public static MvcHtmlString BootstrapLabelFor<TModel, TValue>
(this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TValue>> expression)
{
string html = String.Format(
"<label for='{0}' class='control-label'>{0}</label>",
ExpressionHelper.GetExpressionText(expression));
return new MvcHtmlString(html);
}
私は混乱しています.... 'Expresion>'ここで 'TModel'はあなたのモデルで、' TValue'は投影によって暗示されています。 ? –