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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
A
About on SuperTechFans
量子位
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
T
Threat Research - Cisco Blogs
Spread Privacy
Spread Privacy
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News and Events Feed by Topic
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tenable Blog
V
V2EX
月光博客
月光博客
L
Lohrmann on Cybersecurity
W
WeLiveSecurity
Webroot Blog
Webroot Blog
H
Hacker News: Front Page
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
AI
AI
腾讯CDC
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V2EX - 技术
V2EX - 技术
Martin Fowler
Martin Fowler
博客园 - Franky
I
Intezer
Project Zero
Project Zero
I
InfoQ
P
Privacy International News Feed
C
Check Point Blog
T
The Blog of Author Tim Ferriss
P
Palo Alto Networks Blog
L
LINUX DO - 最新话题
有赞技术团队
有赞技术团队
Cloudbric
Cloudbric
人人都是产品经理
人人都是产品经理
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
SegmentFault 最新的问题
Latest news
Latest news
小众软件
小众软件

博客园 - 为森

NPM设置镜像 WCF 自托管、无配置文件实现jsonp(跨域)的访问 关于nodejs4.0 npm乱码以及离线全局安装时要注意的问题 C# 正则表达式 转自-每日一bo 关于async & await(TAP)异步模型的异常捕获 一个Public的字段引起的,谈谈继承中的new 解决Bootstrap 附加导航(Affix)的问题和使用时若干注意事项 一次小异常的排查,悲剧的无以复加!!! async & await 小扩展大用处,自己扩展一个ForeachRead吧 转 常用工具和技术 implicit和 explicit关键字 解决解密时出现"要解密的数据的长度无效" 或 "填充无效无法被移除" 的错误 EF 的一些不常用的功能 详细说明 配置 Sublime Text 开发node.js(windows)包括sub2和sub3的区别 sql 判断 数据库 表 字段 是否存在 转 WCF中同步和异步通讯总结 关于WCF 解决EF一对一或多对一的删除
MVC 自定义 以表达式树为参数的htmlhelper
为森 · 2014-09-23 · via 博客园 - 为森
public static MvcHtmlString Try<TModel, TProperty>(

    this HtmlHelper<TModel> htmlHelper, //声明这个方法Try是扩展函数,用来扩展HtmlHelper<TModel>

    Expression<Func<TModel, TProperty>> expression//这里声明需要使用时传入表达式树

)

{

    var builder = new TagBuilder("textarea");//建立一个TagBuidlder对象,标签名是textarea

    builder.AddCssClass("ckeditor");//加入一个ckeditor的css类

    builder.MergeAttribute("cols", "80");//加入或修改属性cols为80

    builder.MergeAttribute("name", "editor1");

    builder.MergeAttribute("id", expression.Name); // 加入或修改id属性为表达式树的Name

    var value = ModelMetadata.FromLambdaExpression(

        expression, htmlHelper.ViewData

    ).Model;//通过表达式树从元数据中获取具体对象

    builder.SetInnerText(value.ToString());// 设置内部文本

    return MvcHtmlString.Create(builder.ToString());//将builder对象转换MvcHtmlString对象并返回

}


参考凌鸢的文章。

posted @ 2014-09-23 01:21  为森  阅读(300)  评论()    收藏  举报