在view中有一个dropdownList以及一个按钮,当单击按钮时如何把dropdownList中选中的值传到控制器中?

解决方案 »

  1.   

    Request.Form[dropdownList.Name]or 直接用 html.dropdownList action 用viewmodel接收
      

  2.   

    一般就 post 和get 两种方式,  还不知道传?
      

  3.   


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

  4.   

    [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();
                }
            }
      

  5.   

     m00.ChannelID 这个m00好像还没定义吧?
      

  6.   

    帮我看一下我的代码 @using (Html.BeginForm()) { 
            <div>
                <fieldset>
                    <p>端口:@Html.DropDownList("listchannel", ViewBag.list as IEnumerable<SelectListItem>)</p>         
                    <p><input type="submit" value="保存" /></p>
                </fieldset>
            </div>
         }  public ActionResult Open()
            {
                List<SelectListItem> items = new List<SelectListItem>();
                int i = 1;
                foreach (string s in SerialPort.GetPortNames())
                {
                    items.Add(new SelectListItem { Text = s, Value = (i++).ToString() });
                }
                ViewBag.list = items;
                return View();
            }        [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult Open(FormCollection collection)
            {            Response.Write(int.Parse(Request.Form["list"]));
                return View();
            }
            public class Port
            {
                public int id { get; set; }
                public string Portname { get; set; }
            }选定一个端口点确定后就报错了,Response.Write(int.Parse(Request.Form["list"]));  
    值不能为 null。
    参数名: String 

    请问一下改怎么修改?
    我的本意是想要获得端口名,上面的即使是没出错也只是获得一个id而不是端口名
      

  7.   

    做MVC  如果连get  post都不知道是什么,有什么用。那趁早回去做webform吧。 
      

  8.   

    Response.Write(int.Parse(Request.Form["list"])); Response.Write(int.Parse(Request.Form["listchannel"])); 吧
    list哪存在
      

  9.   

    噢,忘了改了。view代码我是copy 5楼的。我也是刚接触.net的,对get post方式确实还不太了解
      

  10.   

    做webform把最基本的东西都丢了
      

  11.   

    这跟刚接触不刚接触 .net有关系么?貌似html基础知识吧?哎,现在上道的兄弟们都是裸奔上来的,html都不学就开干了。。