I'd like to use model binding to keep my controllers looking cleaner, you can see how much nicer it is using model binding:
public ActionResult Create(Person personToCreate)
{
//Create person here
}
vs
public ActionResult Create(string firstName, string lastName, string address, string phoneNum, string email, string postalCode, string city, string province, string country)
{
//Create person here
}
When doing model binding, we can just use a form with the correct names in the Html.TextBox("")
What about jquery? How can I make sure that when I do a $.post(url, data, callback, dataType)
or a $.ajax(options)
call to Create(Person personToCreate)
that the Person object gets filled properly?
You need to:
Number 2 is the big one in terms of why binding to person can behave differently than specifying individual action arguments for each property. If you have a type with a non-nullable property called "Foo", then failing to supply a foo item in your form will prevent binding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With