是否有可能我创造Html.Label和Html.LabelFor()在ASP.NET MVC LabelTemplates? [英] Is it possible to I create LabelTemplates for Html.Label and Html.LabelFor() in ASP.NET MVC?

查看:322
本文介绍了是否有可能我创造Html.Label和Html.LabelFor()在ASP.NET MVC LabelTemplates?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些有问题的,但实际的原因,我想创建LabelTemplate默认值,就像EditorTemplates或DisplayTemplates。

For reasons that are questionable but practical, I'd like to create LabelTemplate defaults, just like EditorTemplates or DisplayTemplates.

因此​​,而不是这样的:

So instead of this:

@Html.LabelFor(x => x.PropertyName, "Property Name")

或代替本(更好的方式来做到这一点的视图模型):

or instead of this(the better way to do it in a View Model):

[DisplayName("Property Name")]
public string PropertyName{ get; set; } 

我想这样的:

@Html.LabelFor(x => x.PropertyName)

有了这个(类似这样的文件夹中:/查看/共享/ LabelTemplates)

With this (in a folder like this: /Views/Shared/LabelTemplates)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.String>" %>
//Display logic here

您可以帮助codeR OUT?

Can you help a coder out?

推荐答案

创建自己的自定义HTML帮手。

Create your own custom html helper.

<一个href=\"http://develoq.net/2011/how-to-create-custom-html-helpers-for-asp-net-mvc-3-and-razor-view-engine/\" rel=\"nofollow\">http://develoq.net/2011/how-to-create-custom-html-helpers-for-asp-net-mvc-3-and-razor-view-engine/

这篇关于是否有可能我创造Html.Label和Html.LabelFor()在ASP.NET MVC LabelTemplates?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆