ASP.NET MVC, MySQL 및 NHibernate를 사용하여 약간의 사이트를 만들고 있습니다.ModelBinder를 사용하여 유효성 검사를 구현하는 방법
[ModelBinder(typeof(CondicaoBinder))]
public class Contact {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int Age { get; set; }
}
그리고 모델 바인더 :
내가 연락처 클래스가
: 또한public class ContactBinder:IModelBinder {
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
Contact contact = new Contact();
HttpRequestBase form = controllerContext.HttpContext.Request;
contact.Id = Int16.Parse(form["Id"]);
contact.Name = form["Name"];
contact.Age = Int16.Parse(form["Age"]);
return contact;
}
}
을, 나는이 작업을 사용하여 내 데이터베이스를 업데이트하는 양식과 전망을
public ActionResult Edit([ModelBinder(typeof(ContactBinder))] Contact contact) {
contactRepo.Update(contact);
return RedirectToAction("Index", "Contacts");
}
여기까지 모든 것이 정상적으로 작동합니다. 하지만 연락처를 업데이트하기 전에 양식 유효성 검사를 구현해야합니다.
내 질문은 :이 유효성 검사를 어디에서 구현해야합니까? ActionResult 메소드 또는 Model Binder? 아니면 다른 곳에서?
대단히 감사합니다.