惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
N
News and Events Feed by Topic
量子位
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
J
Java Code Geeks
Schneier on Security
Schneier on Security
Google Online Security Blog
Google Online Security Blog
TaoSecurity Blog
TaoSecurity Blog
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
博客园 - 聂微东
T
Tor Project blog
博客园 - Franky
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
罗磊的独立博客
博客园_首页
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
腾讯CDC
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
博客园 - 【当耐特】
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
博客园 - 司徒正美
AWS News Blog
AWS News Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
G
GRAHAM CLULEY
V
V2EX
L
LINUX DO - 最新话题
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家

博客园 - 秃顶的大熊猫

Abp中的sweetalert的版本问题 - 秃顶的大熊猫 - 博客园 Asp.net Core 部署到Azure.cn的一个小问题 在ASP.NET MVC5 及 Visual Studio 2013 中为Identity账户系统配置数据库链接及Code-First数据库迁移 Windows Azure上的Odoo(OpenERP)-2.在Ubuntu虚拟机上部署Odoo(OpenERP) Windows Azure上的Odoo(OpenERP)-1.创建Ubuntu虚拟机,安装PostgreSQL 数据库 Windows Azure上的Odoo(OpenERP) 备忘录:Asp.net mvc中的UpLoad小技巧 真实场景中的SharePoint2010系列(开篇) Asp.Net Mvc 应用程序如何应对不同的URL地址?????,问题解决了 Asp.Net Mvc 应用程序如何应对不同的URL地址????? 为ASP.NET MVC配置基于Active Directory的表单认证方式 MOSS2007-学习笔记-备忘录-单点登录设置(2) MOSS2007-学习笔记-备忘录-单点登录-(1)-"我的网站'? 由公司协同工作平台项目引发的Windows Active Directory(活动目录域)的应用问题 似乎是发现了asp.net ajaxToolkit中TAB控件的一个BUG 动态创建ASP.NET AJAX Control Toolkit中的Accordion控件 学习SQLSERVER2005高可用性数据库镜像的一些心得 贴几张我儿子的照片,大家看看可爱不 哈哈,我回来了!
Html.Label的缺陷及补救办法
秃顶的大熊猫 · 2010-07-31 · via 博客园 - 秃顶的大熊猫
       在最近开发的项目中,应用了Html.LabelFor(TModel)来生成<lable/>标签,同时配合Html.TextBoxFor(TModel)来生成<Input/>标签,效果不错,生成的Html标签
效果如下:
<label for="UserName">标签内容</label>
<input id="UserName" name="UserName" type="text" value="" />
问题产生了:
<Lable>标签内容</Lable>准备实现多国语言版本,使用的是Resources文件。但是,Html.LabelFor()方法只支持Model的DisplayName属性:
public class User
{
    [DisplayName="标签内容"]
    public string DisplayName { get; set; }
    public string SortName { get; set; }
}

问题是DisplayName属性不支持国际化,无法调用Resource中的资源字符串!(此处省略n万字,尝试各种解决方法,就不在此描述了,总之是不成功) 那就换个解决方案吧: <%:Html.Label(Resources.User.Info_State_Header) %> 国际化的问题解决了,但是那个优雅的<label for=”UserName”>属性无法实现了!难道鱼与熊掌不能兼得吗?郁闷啊! 强大的Asp.net Mvc 框架不是吹牛皮吹出来的,上家伙 自定义HtmlHelper方法,直接上代码,大家都是高手,我就不解释了:

namespace System.Web.Mvc
{
    public static class myHtmlHelper
    {
        /// <summary>
        /// 自定义HtmlHelper Label方法,解决for属性和国际化字符串不能同时解决的问题
         /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="?"></param>
        /// <param name="expression"></param>
        /// <param name="DisplayName">要在Label标签中显示的本地化字符串</param>
        /// <returns></returns>
        public static MvcHtmlString Label<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression, string DisplayName)
        {
            string modelName = ExpressionHelper.GetExpressionText(expression);
            TagBuilder tagBuilder = new TagBuilder("label");
            tagBuilder.Attributes.Add("for",modelName);
            tagBuilder.InnerHtml = DisplayName;
            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));
        }
    }
}

啊,问题消失了,继续干活吧,前面的道路还很长呢