I have something like this
public class ViewModel
{
public List<Books> Test {get; set;}
public SelectList List {get; set;}
public ViewModel()
{
Test = new List<Books>();
}
}
public class Books
{
public string SelectedItemFromList {get; set;}
public int forTextbox {get; set;}
}
view
<% for (int i = 0; i < 1; i++)
{ %>
<%: Html.DropDownListFor(m => ViewModel.Books[i].SelectedItemFromList, SelectList ); // works no error
<%: Html.TextBoxFor( m => ViewModel.Books[i].forTextBox) // fails range exception.
<% } %>
I find it odd that the dropdownlist works but the textbox does not. To make the textbox work I would have to do this
Public ViewModel()
{
Test = new List<Books>();
Test.add(new Books() { forTextbox = 1});
}
This makes sense to be because before I was passing to the view an empty list of books but it just so odd that it works for one and not the other. I would think both would fail.