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

推荐订阅源

S
Security Affairs
S
Secure Thoughts
P
Proofpoint News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Schneier on Security
V
Vulnerabilities – Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
Latest news
Latest news
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
T
Troy Hunt's Blog
H
Heimdal Security Blog
美团技术团队
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
V2EX - 技术
V2EX - 技术
G
Google Developers Blog
N
News and Events Feed by Topic
Project Zero
Project Zero
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
IT之家
IT之家
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
博客园_首页
Help Net Security
Help Net Security
AWS News Blog
AWS News Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
Cisco Talos Blog
Cisco Talos Blog
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
Spread Privacy
Spread Privacy
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Hacker News
The Hacker News

博客园 - 秃顶的大熊猫

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));
        }
    }
}

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