zoukankan      html  css  js  c++  java
  • C#_dropdownlist_1

    关于ASP.net MVC 中DropDownList绑定与提交数据

     

    在做 ASP.net MVC项目中,数据绑定也是很关键的,现在以个人经验与大家交流下 ASP.net MVC 中DropDownList绑定与提交数据,由于数据查询较为简单就不列出来了,具体看核心代码部分吧。

    数据表:

    DropDownList绑定

            public ActionResult ColumnManage()         {             ViewData["listchannel"= new SelectList(b00.ListChannel(), "ChannelID""ChannelName");             return View();         }

     其中b00.ListChannel()是BLL层中的

    View中

    复制代码
        <h2>栏目管理</h2>     <% SelectList categories = ViewData["listchannel"as SelectList; %>     <% using (Html.BeginForm()) { %>         <div>             <fieldset>                 <legend>添加栏目</legend>                 <p>栏目名称:<input type="text" id="columnname" style=" 100px;"/></p>                 <p>上级目录:<select><option></option></select></p>                 <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 序:<input type="text" id="sort" style=" 30px;"/></p>                 <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 道:<%=Html.DropDownList("listchannel", categories)%></p>                          <p><input type="submit" value="保存" /></p>             </fieldset>         </div>     <% } %>
    复制代码

    显示效果如下:

    在提交时注意 DropDownList 还需要绑定一次

    复制代码
            [AcceptVerbs(HttpVerbs.Post)]         public ActionResult ColumnManage(string columnname,string sort)         {             try             {                 ViewData["listchannel"= new SelectList(b00.ListChannel(), "ChannelID""ChannelName");                 m00.ChannelID = int.Parse(Request.Form["listchannel"]);                 Response.Write(m00.ChannelID);                 return View();             }             catch             {                 return View();             }         }
    复制代码

    这样就可以提交获取DropDownList的 ID值了

  • 相关阅读:
    NYOJ232 How to eat more Banana
    NYOJ716 River Crossing(第六届河南省程序设计大赛)
    HDOJ1847 Good Luck in CET4 Everybody!
    NYOJ234 吃土豆
    HDOJ1850Being a Good Boy in Spring Festival
    HDOJ2176 取(m堆)石子游戏
    NYOJ78 圈水池(简单凸包)
    POJ1656 Counting Black (二维树状数组)
    HDOJ1892 See you~(二维树状数组)
    取石子问题 – 1堆
  • 原文地址:https://www.cnblogs.com/MarchThree/p/3734699.html
Copyright © 2011-2022 走看看