刚开始玩knockout.Js这是一个很棒的框架史蒂夫真的很好用这个.我现在似乎无法做的一件事就是用我的Html Helpers来表达它.所以对于exmaple我有:
<%: Html.TextBoxFor(model => model.Division) %>
Run Code Online (Sandbox Code Playgroud)
但是我会在那上面使用数据绑定,但是在那一刻我无法将"数据绑定"属性放入帮助程序中.我之前使用过@class,Id等属性,但是由于 - 任何想法,这个都很棘手.我试过:
<%: Html.TextBoxFor(model => model.SupplierName, new { data-bind = "SupplierName"}) %>
Run Code Online (Sandbox Code Playgroud)
和
<%: Html.TextBoxFor(model => model.SupplierName, new { "data-bind"" = "SupplierName"}) %>
Run Code Online (Sandbox Code Playgroud)
但没有快乐.我们大量使用编辑器和文本框帮助器,我真的很想将它们整合到项目中,并将其淘汰.
任何有用的帮助
对不起,如果这是一个愚蠢的菜鸟问题,请温柔地对待我,我正在努力学习......
我想测试模型和控制器之类的属性方法.主要是为了确保他们有正确的属性,即必需.但我也将它用作扩展方法和Lambdas的实验.
我想要的是一种方法,当被赋予某种东西时,它就像是一种东西
Controller controller = new Controller();
controller.MethodName(params).HasAttribute<AttributeName>();
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一些扩展方法,但没有达到这个程度.我确信这应该很简单,但似乎无法使我的泛型等正确.
我的问题是从已从数据库返回的Linq2Sql对象中保护Viewmodel.我们已经在一些领域做到了这一点并且有一个很好的分层模式,但是最新的项目要求使用一些枚举,这引起了全面的麻烦.目前我们从数据库撤回然后使用Automapper将水合(或变平)到我们的View模型中,但是模型中的枚举似乎导致了Automapper的问题.我已经尝试创建自定义resovler,它已满足我所有其他映射要求,但它在此实例中不起作用.
代码示例如下:
public class CustomerBillingTabView{
public string PaymentMethod {get; set;}
...other details
}
public class BillingViewModel{
public PaymentMethodType PaymentMethod {get; set;}
...other details
}
public enum PaymentMethodType {
Invoice, DirectDebit, CreditCard, Other
}
public class PaymentMethodTypeResolver : ValueResolver<CustomerBillingTabView, PaymentMethodType>
{
protected override PaymentMethodType ResolveCore(CustomerBillingTabView source)
{
if (string.IsNullOrWhiteSpace(source.PaymentMethod))
{
source.PaymentMethod = source.PaymentMethod.Replace(" ", "");
return (PaymentMethodType)Enum.Parse(typeof(PaymentMethodType), source.PaymentMethod, true);
}
return PaymentMethodType.Other;
}
}
CreateMap<CustomerBillingTabView, CustomerBillingViewModel>()
.ForMember(c => c.CollectionMethod, opt => opt.ResolveUsing<PaymentMethodTypeResolver>())
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
[ArgumentException: Type provided must be an Enum.
Parameter …
Run Code Online (Sandbox Code Playgroud) 真的不确定这里发生了什么,但我在一个项目中玩pex和moles然后我得到了pex来为Web客户端生成测试,这是MVC.这导致了项目中的各种构建问题,因此我将项目还原(使用HG进行源代码控制).我仍然遇到所有相同的构建问题,其中包括缺少引用和与缺少引用相关的其他错误.当我删除解决方案中的引用时,例如system.web.mvc和system.componentmodel.dataannotations,并尝试从GAC重新添加它们,它们在GAC中不可见.我无法理解pex如何做到这一点.现在,我在visual studio中的所有项目都有与DataAnnotations,Mvc和其他一些参考文献相同的问题吗?我对他们中的任何一个都无能为力.我也注意到pex论坛的所有链接似乎已经死了?
我想我可以恢复我的大部分工作,因为它是一个虚拟机,我有一个不老的快照加上我从Dropbox工作,所以可以把我所有的源恢复.我只是无法理解这是如何发生任何身体有任何建议,相同性质的经验.我真的开始喜欢pex和鼹鼠,但这让我很开心.
c# ×2
.net-4.0 ×1
asp.net-mvc ×1
automapper ×1
enums ×1
html-helper ×1
knockout.js ×1
pex ×1
reference ×1
tdd ×1
viewmodel ×1