我有一個解決方法創建我的自定義@ Html.LabelFor()和@ html.DescriptionFor()助手。
我的幫助:
namespace MyCMS.Helpers
{
public static class Html
{
public static MvcHtmlString DescriptionFor<TModel, TValue>(
this HtmlHelper<TModel> self,
Expression<Func<TModel, TValue>> expression)
{
var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData);
var description = Localizer.Translate(metadata.Description);
return MvcHtmlString.Create(string.Format(@"<span class=""help-block"">{0}</span>", description));
}
public static MvcHtmlString LabelFor<TModel, TValue>(
this HtmlHelper<TModel> self,
Expression<Func<TModel, TValue>> expression,
bool showToolTip
)
{
var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData);
var name = Localizer.Translate(metadata.DisplayName);
return MvcHtmlString.Create(string.Format(@"<label for=""{0}"">{1}</label>", metadata.PropertyName, name));
}
}
}
我的看法是:
@using MyCMS.Localization; @using MyCMS.Helpers;
<div class="clearfix ">
@Html.LabelFor(model => model.RecordDetails.TitleAlternative)
<div class="input">
@Html.TextBoxFor(model => model.RecordDetails.TitleAlternative, new { @class = "xxlarge" })
@Html.ValidationMessageFor(model => model.RecordDetails.TitleAlternative)
@Html.DescriptionFor(model => model.RecordDetails.TitleAlternative)
</div>
</div>
,我可以用我的定位方法:)
謝謝大家再次...
我不會僅僅說你*可*用於該用途的資源文件;這就是你認爲在.NET中處理本地化的方式。 – Aaronaught
謝謝你們,我在下面發佈了我的解決方案 – Orhaan