简体   繁体   English

如何使用System.Web.Mvc.SelectListItem

[英]How to use System.Web.Mvc.SelectListItem

如何将ASP.NET MVC控制器使用System.Web.Mvc.SelectListItem。

1.Wrote SelectItemList collection generate code in Controller/Action method. 1.Write 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"}
                       };

2.Wrote render code in Views aspx. 2.在Views aspx中编写渲染代码。

<% using (Html.BeginForm()) { %>
  <% = Html.DropDownList("list") %>

  <input type="submit" value="send" />
<% } %>

3.Get posted value code in Controller/Action method with ModelBinder. 3.使用ModelBinder在Controller / Action方法中获取过帐值代码。

[HttpPost]
public ActionResult Index(string list)
{
  // process code
}

How about this code? 这个代码怎么样? Best,regard. 最良好的问候。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;System.Web.Mvc.SelectListItem&#39; 不包含名为 &#39;id&#39; #2 的属性 - 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'id' #2 ''System.Web.Mvc.SelectListItem' 不包含'string'的定义' - ''System.Web.Mvc.SelectListItem' does not contain a definition for 'string'' 获取 System.Web.Mvc.SelectListItem 作为 DropDownList 的选项 - Getting System.Web.Mvc.SelectListItem as options of DropDownList 如何解决“'System.Collections.Generic.List<string> ' 到 'System.Collections.Generic.List<system.web.mvc.selectlistitem> ''</system.web.mvc.selectlistitem></string> - how to resolve "'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<System.Web.Mvc.SelectListItem>'' 为什么我的Html.DropDownList给我一个用“ System.Web.Mvc.SelectListItem”字符串填充的列表? - Why does my Html.DropDownList give me a list populated with “System.Web.Mvc.SelectListItem” strings? 为什么我的Html.DropDownList会产生一个列表,其中填充了“ System.Web.Mvc.SelectListItem”字符串? - Why would my Html.DropDownList yield a list filled with “System.Web.Mvc.SelectListItem” strings? 为什么我在DropDownList中获取“System.Web.Mvc.SelectListItem”? - Why I am getting “System.Web.Mvc.SelectListItem” in my DropDownList? 无法从 'System.Collections.Generic.IEnumerable 转换<system.web.mvc.selectlistitem>在将 ViewData 用于 @Html.DropDownListFor 时,将 ' 转换为 'string'</system.web.mvc.selectlistitem> - cannot convert from 'System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>' to 'string' while using ViewData for @Html.DropDownListFor 无法加载文件或程序集“System.Web.Mvc”。 如何使用正确的参考? - Could not load file or assembly 'System.Web.Mvc' . How to use the correct reference? 如何从web.config读取系统值并在ASP.NET MVC C#方法中使用 - How to read system value from web.config and use in ASP.NET MVC C# method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM