Asp.net mvc 3 Asp.net MVC3中默认编辑器和显示模板的位置是什么?
安装Asp.Net MVC 3时,默认的Razor编辑器和显示模板(例如String.cshtml、DateTime.cshtml)位于何处?如果您有DotPeek或Reflector,您可以在其中查找类型Asp.net mvc 3 Asp.net MVC3中默认编辑器和显示模板的位置是什么?,asp.net-mvc-3,Asp.net Mvc 3,安装Asp.Net MVC 3时,默认的Razor编辑器和显示模板(例如String.cshtml、DateTime.cshtml)位于何处?如果您有DotPeek或Reflector,您可以在其中查找类型DefaultDisplayTemplates,您将找到模板。但请注意,它们是代码格式的,而不是WebForm或razor格式,因此解释起来有点困难 StringTemplate internal static string StringTemplate(HtmlHelper html) {
DefaultDisplayTemplates
,您将找到模板。但请注意,它们是代码格式的,而不是WebForm或razor格式,因此解释起来有点困难
StringTemplate
internal static string StringTemplate(HtmlHelper html)
{
return html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue);
}
internal static string DecimalTemplate(HtmlHelper html)
{
if (html.ViewContext.ViewData.TemplateInfo.FormattedModelValue == html.ViewContext.ViewData.ModelMetadata.Model)
html.ViewContext.ViewData.TemplateInfo.FormattedModelValue = (object) string.Format((IFormatProvider) CultureInfo.CurrentCulture, "{0:0.00}", new object[1]
{
html.ViewContext.ViewData.ModelMetadata.Model
});
return DefaultDisplayTemplates.StringTemplate(html);
}
(我找不到默认的日期时间模板)
DecimalTemplate
internal static string StringTemplate(HtmlHelper html)
{
return html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue);
}
internal static string DecimalTemplate(HtmlHelper html)
{
if (html.ViewContext.ViewData.TemplateInfo.FormattedModelValue == html.ViewContext.ViewData.ModelMetadata.Model)
html.ViewContext.ViewData.TemplateInfo.FormattedModelValue = (object) string.Format((IFormatProvider) CultureInfo.CurrentCulture, "{0:0.00}", new object[1]
{
html.ViewContext.ViewData.ModelMetadata.Model
});
return DefaultDisplayTemplates.StringTemplate(html);
}
没有默认模板。Razor
Editor
和Display
方法是HtmlHelper类的扩展方法。您可以使用它们,也可以开发自己的扩展方法,如本例所示
public static MvcHtmlString MyTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression)
{
MvcHtmlString result = InputExtensions.TextBoxFor(helper, expression);
// do modification to result
return result;
}
public static MvcHtmlString MyTextBoxFor(此HtmlHelper,表达式)
{
MvcHtmlString result=InputExtensions.TextBoxFor(helper,expression);
//对结果进行修改
返回结果;
}
您是否正在寻找编辑器和显示方法扩展??(比如@Html.DisplayFor(x=>x.Name))@MaxZerbini-I计划使用这些扩展。我想摆弄一下这些模板的完整默认集。这些不是模板。这些是对象HtmlHelper的扩展方法。您可以使用它们,也可以开发扩展方法。它们不是Max Zerbini提到的模板。但是,您可以通过将诸如String.cshtml之类的部分放在“视图”下的“共享\EditorTemplates”文件夹中来创建它们。@MaxZerbini请将您的评论作为答案,我接受