我有一个小应用程序,我在创建一个客户
[Authorize] [AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateCustomer(GWCustomer customer) { if (string.IsNullOrEmpty(customer.CustomerName)) { ModelState.AddModelError("CustomerName","The name cannot be empty"); } //... if (ModelState.IsValid) { //insert in db } }
我的问题是GWCustomer对象有一个Id,它是主键,不能为null.这使得验证框架将其标记为错误.但这不是一个错误,我还没有创建客户,现在应该是null,直到它被保存.我该如何绕过这个?还是解决它?
我永远不会在DB中插入它,因为ModelState永远不会有效.
编辑我正在使用Linq to sql和存储库模式.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。