This might seem a pretty simple question;
I'm using the Pubs database with the Authors table. I have used Linq to SQL as my data access and I've created an edit view with ASP.net MVC. The last property of an author model is 'contract' which is a true/false value. What I am attempting to do is to create a DropDownList with the values 'yes' or 'no' and bind to that list when the pages loads with the value from the authors model.
Here is what I have for the DropDownList markup:
Html.DropDownList("dropDownList", new[]
{
new SelectListItem { Text = "Yes", Value = "true" },
new SelectListItem { Text = "No", Value = "false" }
})
The view model comes back as this:
model.contract
which is a boolean value of 'true' or 'false'.
What would be the easiest way set the correct value in the dropdown list using the model's value?
Answer
Instead of using just :
model.contract
I went ahead and used:
Model.contract
Which accessed the page level model which is where I needed to be. After that everything else came together.