I have a model like so:
class Model {
public IList<Item> Items { get; set; }
}
class Item { public int Id { get; set; } }
I am sending a request to an action method that takes a Model as a parameter. The request contains the following key-value pair: "Items=" (i. e.
Items=null
). The default model binder sets Items to be a list of 1 null
item, where I want the list property itself to be null
(or at least empty).
Is there any way to accomplish this?
Obviously, I could do some sort of custom model binding, but I'd prefer a solution that would work using the default model binder (perhaps modifying the formatting of the request).
You could add a property to the class with the behavior you want.
Assuming you use jQuery, I would extend it to be able to serialize the form to object
Then I could simply get the form into a variable:
Do my test to know if I want to delete a property
Then proceed normally with submitting the data with ajax.