Myt*_*ank 3 database asp.net asp.net-mvc
如何为asp.net mvc控制器使用System.Web.Mvc.SelectListItem.
小智 8
1.Wote SelectItemList集合在Controller/Action方法中生成代码.
ViewData["list"] = new List<SelectListItem>
{
new SelectListItem {Text = "January", Value = "1"},
new SelectListItem {Text = "February", Value = "2"},
new SelectListItem {Text = "March", Value = "3"}
};
Run Code Online (Sandbox Code Playgroud)
2.在Views aspx中编写渲染代码.
<% using (Html.BeginForm()) { %>
<% = Html.DropDownList("list") %>
<input type="submit" value="send" />
<% } %>
Run Code Online (Sandbox Code Playgroud)
3.使用ModelBinder在Controller/Action方法中发布值代码.
[HttpPost]
public ActionResult Index(string list)
{
// process code
}
Run Code Online (Sandbox Code Playgroud)
这段代码怎么样?最良好的问候.
| 归档时间: |
|
| 查看次数: |
6301 次 |
| 最近记录: |