Questions tagged «mvccontrib»

21
反映参数名称:滥用C#lambda表达式还是语法光彩?
我正在看MvcContrib Grid组件,我被Grid语法中使用的句法把戏迷住了,但同时又被它击退了: .Attributes(style => "width:100%") 上面的语法将生成的HTML的style属性设置为width:100%。现在,如果您要注意,则从表达式中参数的名称推导出“ style”(在任何地方都未指定)!我不得不对此进行深入研究,并发现“魔术”发生的位置: Hash(params Func<object, TValue>[] hash) { foreach (var func in hash) { Add(func.Method.GetParameters()[0].Name, func(null)); } } 因此,确实,代码使用形式上的,编译时的参数名称来创建属性名称-值对的字典。最终的语法构造确实非常具有表现力,但同时也非常危险。lambda表达式的一般用法允许替换使用的名称而没有副作用。我在书中看到一个例子,说collection.ForEach(book => Fire.Burn(book))我知道我可以用代码编写collection.ForEach(log => Fire.Burn(log)),这意味着相同的事情。但是突然之间有了MvcContrib Grid语法,我发现了可以根据我为变量选择的名称主动查找并做出决策的代码! 那么,这是C#3.5 / 4.0社区和lambda表达式爱好者的惯常做法吗?还是我不必担心一个流氓特技特立独行者?

10
ASP.NET MVC部分视图:输入名称前缀
假设我有喜欢的ViewModel public class AnotherViewModel { public string Name { get; set; } } public class MyViewModel { public string Name { get; set; } public AnotherViewModel Child { get; set; } public AnotherViewModel Child2 { get; set; } } 在视图中,我可以使用 <% Html.RenderPartial("AnotherViewModelControl", Model.Child) %> 在部分我会做 <%= Html.TextBox("Name", Model.Name) %> or …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.