I am developing a small site using ASP.NET MVC, MySQL and NHibernate.
I have a Contact class:
[ModelBinder(typeof(CondicaoBinder))]
public class Contact {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int Age { get; set; }
}
And binding to the model:
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;
}
}
In addition, I have a view with a form to update my database using this action:
public ActionResult Edit([ModelBinder(typeof(ContactBinder))] Contact contact) {
contactRepo.Update(contact);
return RedirectToAction("Index", "Contacts");
}
So far, everything is working fine here. But before updating my contact, I have to do a form check.
My question is: Where should I perform this check? In the ActionResult method or in the Model Binder? Or somewhere else?
Many thanks.
source
share