How to use System.Web.Mvc.SelectListItem for asp.net mvc controller.
+2
A:
1.Wrote SelectItemList collection generate code in Controller/Action method.
ViewData["list"] = new List<SelectListItem>
{
new SelectListItem {Text = "January", Value = "1"},
new SelectListItem {Text = "February", Value = "2"},
new SelectListItem {Text = "March", Value = "3"}
};
2.Wrote render code in Views aspx.
<% using (Html.BeginForm()) { %>
<% = Html.DropDownList("list") %>
<input type="submit" value="send" />
<% } %>
3.Get posted value code in Controller/Action method with ModelBinder.
[HttpPost]
public ActionResult Index(string list)
{
// process code
}
How about this code? Best,regard.
takepara
2009-10-19 15:30:38