随笔 - 8  文章 - 0  评论 - 84 

最新评论

共2页: 1 2 下一页 
Re:Asp.Net Mvc: 浅析TempData机制 JSK 2012-01-08 16:34  
楼主讲的非常清晰,顶!
Re:Asp.Net Mvc: Implement your custom ModelBinder 桀骜的灵魂 2011-06-18 10:28  
请问楼主,文章中的代码的图片样式怎么搞的?
收藏了 这几篇MVC文章 很实用
Re:也谈实体验证(Entity Validation) 修改 2009-12-25 10:31  
根据你写的修改了一下, 主要加入了,一个实体有多种验证方式, 我修改成了,实体要验证什么有使用者决定, usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespaceConsoleApplication2 { classProgram { staticvoidMain(string[]args) { Useru=newUser(){Name="Dylan",Age=17}; u.CheckList.Add(u.CheckList_Age); u.CheckList.Add(u.CheckList_Name); IEnumerable<String>errorList=u.Check(); foreach(stringainerrorList) { Console.WriteLine(a); } Console.Read(); } } publicclassEntityBase { publicList<CustomePredicate<User>>CheckList=newList<CustomePredicate<User>>(); publicvirtualIEnumerable<String>Check() {returnnull;} } publicclassUser:EntityBase { publicCustomePredicate<User>CheckList_Name=newCustomePredicate<User>("Namelenghtxiao20",u=>u.Name.Length<20); publicCustomePredicate<User>CheckList_Age=newCustomePredicate<User>("Agexiao20",user=>user.Age<20); privateValidator<User>validate=newValidator<User>(); publicStringName {get;set;} publicInt32Age {get;set;} publicUser() :base() {} publicoverrideIEnumerable<String>Check() { for(inti=0;i<CheckList.Count;i++) { validate.Validate(CheckList[i].ErrorMessage,CheckList[i].Predicate,this); } returnvalidate.ErrorList; } } publicclassCustomePredicate<T>whereT:EntityBase { privatePredicate<T>m_Predicate=null; publicPredicate<T>Predicate {get{returnm_Predicate;}} privateStringm_erroeMessage=String.Empty; publicStringErrorMessage {get{returnm_erroeMessage;}} publicCustomePredicate(StringerrorMessage,Predicate<T>p) { m_erroeMessage=errorMessage; m_Predicate=p; } } publicclassValidator<T>whereT:EntityBase { privateList<String>m_errorlist=newList<String>(); publicIEnumerable<String>ErrorList { get{returnm_errorlist;} } publicvoidValidate(StringerrorMessage,Predicate<T>predicate,Tentity) { if(predicate(entity)) m_errorlist.Add(errorMessage); } } }
Re:Asp.Net Mvc: 应用BindAttribute Bazishan 2009-11-19 16:27  
写的不错,顶!
支持
Re:也谈实体验证(Entity Validation) Tristan G 2009-07-13 16:53  
[quote]xzcvzxcvzxcvxzcv: 什么烂玩意 还有说人NB [/quote] 那是那是,您才NB
Re:也谈实体验证(Entity Validation) xzcvzxcvzxcvxzcv 2009-07-13 16:49  
什么烂玩意 还有说人NB
re: Asp.Net Mvc: 浅析TempData机制 Nick Wang (懒人王) 2009-06-02 14:15  
@xxxxxxxxxxxxxxxxx
问题是,为什么当前页面(action)设置了TempData还要再获取一下呢?

大家应该将目光放到框架鼓励的使用方法上,而不是如何破坏规则。
re: Asp.Net Mvc: 浅析TempData机制 xxxxxxxxxxxxxxxxx 2009-06-02 14:09  
--引用--------------------------------------------------
Nick Wang: TempData中的数据迅速被清除是因为它叫“Temp”Data,既然是Temp的当然要很快就失效了,否则就不Temp了。

正是由于http是无状态的,因此在http的不同请求中共享状态信息是不符合无状态的特点的,但是从应用的角度又不可能完全没有状态,所以才用TempData来解决问题,所以TempData中的数据一旦被访问,下次就访问不到了,因为它已经完成了历史使命了
--------------------------------------------------------
不对啊,可能会被访问两次,当前页面设置了TempData,可以访问,这个时候并没有调用Load和Save方法,再打开另一个页面,也可以访问到,这个时候才调用了Load和Save方法,TempData才消失
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-17 10:14  
--引用--------------------------------------------------
老衲2009: 楼主能分享下你的IDE配色背景的RGB值吗?感激不尽。。
--------------------------------------------------------
255 255 181
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-17 10:13  
--引用--------------------------------------------------
kyorry: 牛人啊,学习了
但是我觉得后面的做法和前面的if其实本质是一样的,只是语法的变化
如果真能像EntLib的Validate那样,在实体上加标签,就好了
收藏!
--------------------------------------------------------
那就是另一种解决方案了。
re: 也谈实体验证(Entity Validation) 李涛 2009-05-16 16:38  
RGB大概是:255,255,173
re: 也谈实体验证(Entity Validation) 老衲2009 2009-05-16 10:48  
楼主能分享下你的IDE配色背景的RGB值吗?感激不尽。。
re: 也谈实体验证(Entity Validation) kyorry 2009-05-16 09:49  
牛人啊,学习了
但是我觉得后面的做法和前面的if其实本质是一样的,只是语法的变化
如果真能像EntLib的Validate那样,在实体上加标签,就好了
收藏!
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 20:52  
--引用--------------------------------------------------
Jeffrey Zhao: C#多nb。
--------------------------------------------------------
确实nb
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 20:52  
@rex xiang@匿名
真是很有动手精神啊。
re: 也谈实体验证(Entity Validation) Jeffrey Zhao 2009-05-15 18:16  
C#多nb。
re: 也谈实体验证(Entity Validation) HCOONa 2009-05-15 18:04  
很厉害啊,学习了
re: 也谈实体验证(Entity Validation) rex xiang@匿名 2009-05-15 16:56  
俺稍微篡改了下,写成这样了.
-------------
public static class ValidateExtension {
public static ValidateResult<T> Validate<T>(this T target, Predicate<T> predicate, string errorMessage) {
var result = new ValidateResult<T>(target);

if (!predicate(target)) {
result.Errors.Add(errorMessage);
}

return result;
}

public static ValidateResult<T> Validate<T>(this ValidateResult<T> target, Predicate<T> predicate, string errorMessage) {

if (!predicate(target.Entity)) {
target.Errors.Add(errorMessage);
}

return target;
}
}

public class ValidateResult<T> {
internal List<string> Errors { get; set; }
internal T Entity { get; private set; }

internal ValidateResult(T entity) {
Errors = new List<string>();

Entity = entity;
}

public string[] ErrorMessages { get { return Errors.ToArray(); } }
}
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 13:54  
--引用--------------------------------------------------
老李飞刀: 是不是可以用Enterprise Library 中的Validation , 会不会更方便!
<a href="http://msdn.microsoft.com/en-us/library/dd140088.aspx" target="_new">http://msdn.microsoft.com/en-us/library/dd140088.aspx</a>
--------------------------------------------------------
不反对。
如果我不用Ent...
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 13:52  
--引用--------------------------------------------------
麒麟.NET: 兄台IDE的配色不错,很舒服,呵呵
--------------------------------------------------------
哈哈,照顾眼睛啊
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 13:51  
--引用--------------------------------------------------
daodao: 看不懂最后一个Check()用的是什么语法?有相关的介绍吗?
--------------------------------------------------------
没什么特别啊?就是折个行
re: 也谈实体验证(Entity Validation) 麒麟.NET 2009-05-15 13:50  
兄台IDE的配色不错,很舒服,呵呵
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 13:50  
--引用--------------------------------------------------
huinet: 我是新手,问个问题。
代码中的 =&gt; 是什么运算符。
--------------------------------------------------------
Lambda表达式
http://msdn.microsoft.com/zh-cn/library/bb397687.aspx
re: 也谈实体验证(Entity Validation) Q.Lee.lulu 2009-05-15 13:30  
@老李飞刀
我也是这认为来着...
re: 也谈实体验证(Entity Validation) 老姜 2009-05-15 11:27  
学习了
re: 也谈实体验证(Entity Validation) 老李飞刀 2009-05-15 11:26  
是不是可以用Enterprise Library 中的Validation , 会不会更方便!
http://msdn.microsoft.com/en-us/library/dd140088.aspx
re: 也谈实体验证(Entity Validation) oec2003 2009-05-15 11:13  
这种方式确实写起来很方便也很舒服
老赵在讲mvc时 写过类似的
re: 也谈实体验证(Entity Validation) daodao 2009-05-15 11:09  
看不懂最后一个Check()用的是什么语法?有相关的介绍吗?
re: 也谈实体验证(Entity Validation) JimLiu 2009-05-15 10:48  
不错,挺漂亮的!
re: 也谈实体验证(Entity Validation) huinet 2009-05-15 10:03  
我是新手,问个问题。
代码中的 => 是什么运算符。
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:42  
--引用--------------------------------------------------
阿鹏: 呵,写的不错。
我之前也一直在头痛服务端验证与客户端验证的问题。
不过现在找到一种解决方案了:jquery.validate验证客户端,Enterprise validation验证服务端。使用MVC的ModelState来显示错误信息。代码漂亮多了。不过webforms由于没有ModelState。有点小麻烦。
--------------------------------------------------------
我也是前台jQ。
后台嘛,感觉Ent比较重,所以比较少用。
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:41  
--引用--------------------------------------------------
Anytao: 实体验证,EntLib的Validation组件提供了更好的解决方式:-)
--------------------------------------------------------
没错。
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:39  
--引用--------------------------------------------------
GUO Xingwang: 其实我们有的时候学习的不是知识本身,而是学习楼主处理问题的思路与方法,楼主,you are very NB!
--------------------------------------------------------
过奖了,只是一点小技巧
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:38  
--引用--------------------------------------------------
黄泉天上来: 我觉得楼主还是把代码粘上 要不 不好拷贝 哈哈哈
--------------------------------------------------------
贴代码感觉有点乱,没掌握技巧贴不来。。
所以还是贴图比较快一点啊,呵呵
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:37  
--引用--------------------------------------------------
徐少侠: 顶博主

不用if和for是我一直以来的的追求
--------------------------------------------------------
握手!
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:37  
--引用--------------------------------------------------
feiyang: 楼主的截图用的什么工具,挺漂亮的
可否告知一下?
--------------------------------------------------------
WinSnap
re: 也谈实体验证(Entity Validation) 阿鹏 2009-05-15 09:36  
呵,写的不错。
我之前也一直在头痛服务端验证与客户端验证的问题。
不过现在找到一种解决方案了:jquery.validate验证客户端,Enterprise validation验证服务端。使用MVC的ModelState来显示错误信息。代码漂亮多了。不过webforms由于没有ModelState。有点小麻烦。
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:36  
--引用--------------------------------------------------
Astral.Road: 放在实体内?
--------------------------------------------------------
这个问题可能要另开贴讨论了。有机会我们再来研究一下。:)
re: 也谈实体验证(Entity Validation) Anytao 2009-05-15 09:35  
实体验证,EntLib的Validation组件提供了更好的解决方式:-)
re: 也谈实体验证(Entity Validation) Tristan G 2009-05-15 09:34  
哎,昨晚显然头脑不是很清醒,最后的Check()方法有点小错误,第三个Validate需要加上对UserName的null检查,回家再更新了。
re: 也谈实体验证(Entity Validation) anonymous123 2009-05-15 09:33  
不错不错!
re: 也谈实体验证(Entity Validation) GUO Xingwang 2009-05-15 09:05  
其实我们有的时候学习的不是知识本身,而是学习楼主处理问题的思路与方法,楼主,you are very NB!
re: 也谈实体验证(Entity Validation) 黄泉天上来 2009-05-15 09:04  
我觉得楼主还是把代码粘上 要不 不好拷贝 哈哈哈
re: 也谈实体验证(Entity Validation) Q.Lee.lulu 2009-05-15 08:58  
哈哈,哇哈哈....
re: 也谈实体验证(Entity Validation) 徐少侠 2009-05-15 08:42  
顶博主

不用if和for是我一直以来的的追求
re: 也谈实体验证(Entity Validation) 老鼠 2009-05-15 08:37  
不错
re: 也谈实体验证(Entity Validation) feiyang 2009-05-15 08:34  
楼主的截图用的什么工具,挺漂亮的
可否告知一下?
re: 也谈实体验证(Entity Validation) 温景良(Jason) 2009-05-15 08:12  
up
共2页: 1 2 下一页