ASP.NET MVC 2 - Select List Item without Database
I am still struggling with this--
All I am after is an order form, initially it will be a laptop order form but it might be a computer, printer etc in the future. So I have an Order Controller with a Laptop Action which makes a new laptop model. In the model I want to collect various information such as Customer Name, Customer Details etc. In my MODEL I also want to keep a Select List but I've been trying for ages and just cant seem to get it running. My laptop model has this:
--Laptop Model Select List
public SelectList screenSize = new SelectList(new[]
{
new SelectListItem { Text = "11.6", Value = "11.6" },
new SelectListItem { Text = "15.6", Value = "15.6" },
new SelectListItem { Text = "17", Value = "17" }
}, "Value", "Text");
In the controller I accept the laptop on the post
[HttpPost]
public ActionResult Index(Laptop laptopToEmail)
{
if (ModelState.IsValid)
{
...send an email
}
else return View(laptopToEmail)
}
In the view i am able to render out the list of items and I have a select list but I dont get a value passed to the email when i use
laptopToEmail.screenSize.SelectedValue
The view has this helper.
<%: Html.DropDownList("screenSize",Model.screenSize) %>
Am i missing something here? Surely it c开发者_Go百科ant be this difficult to get a select list to work without a database in MVC.
You know, all these neato MVC Html helpers do have HTML equivalents. For a 2-item drop down, why not just write a bit of html:
<select>
<option value="a">Option A</option>
<option value="b">Option b</option>
</select>
精彩评论