I have a list of items in my form which are named like this...
<input type="text" id="ListItem1" name="ListItem1">
<input type="text" id="ListItem2" name="ListItem2">
<input type="text" id="ListItem3" name="ListItem3">
I want to create a custom model binder which converts these in to model with this structure...
public class MyModel
{
public IEnumerable<MyModelItem> Items {get; set;}
}
public class MyModelItem
{
public int Id { get; set; }
public string Value { get; set; }
}
So each ListItem should be converted to a MyModelItem with id equal to the number at the end of the input id and value set to the value on the input field.
In ASP.Net MVC 1.0 I could iterate over the bindingContext.ValueProvider.Keys
collection and check for key.StartsWith("ListItem")
to find all input items in this format.
The new IValueProvider interface in ASP.Net MVC 2 does not have a keys collection and I cannot iterate over that interface. How can I access these values which I only know the prefix for at design time in ASP.Net MVC 2?
If you want to iterate over the form values, use Request.Form.
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