Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
View 当我们使用mvc4选择项目时,如何在控制器中获取dropdownlist id_View - Fatal编程技术网

View 当我们使用mvc4选择项目时,如何在控制器中获取dropdownlist id

View 当我们使用mvc4选择项目时,如何在控制器中获取dropdownlist id,view,View,我从数据库中填写了dropdownlst。现在我需要在控制器中获取所选的值并进行一些操作。但空数据将被删除。我试过的代码 ##View## @using (Html.BeginForm()) { @Html.DropDownList("SupplierId", ViewBag.PurSupName as SelectList, new {@class = "form-control",style = "width: 200px;",id="supId"}) }

我从数据库中填写了dropdownlst。现在我需要在控制器中获取所选的值并进行一些操作。但空数据将被删除。我试过的代码

##View##
@using (Html.BeginForm()) {      

 @Html.DropDownList("SupplierId", ViewBag.PurSupName as SelectList, new  {@class = "form-control",style = "width: 200px;",id="supId"})         
}


## Controller ##


 public ActionResult ItemPurchased()    
 {   
       POS_DBEntities2 db = new POS_DBEntities2();
       var query = from i in db.TBL_Account
                   where i.Type == "supplier"
                   select i;
       ViewBag.PurSupName = new SelectList(query, "AccountId", "AccountName");            
       return PartialView("ItemPurchased", new List<PurchasedItem>());
 }


##Controller##

 public ActionResult GetPurchasedItem()          
 {   
     var optionsValue = this.Request.Form.Get("SupplierId");           
     return View();
 }

您可以尝试以下更改

@using (Html.BeginForm("GetPurchasedItem","YourController")) {      

 @Html.DropDownList("SupplierId", ViewBag.PurSupName as SelectList, new  {@class = "form-control",style = "width: 200px;",id="supId"})   
  <input type="submit" value="OK" />      
}

它应该可以正常工作。

您必须在.cshtml中填写javascript中的值。请同时提供从浏览器执行ItemPurchased方法的代码。
[HttpPost]
public ActionResult GetPurchasedItem(string SupplierId)          
 {   
     var optionsValue = SupplierId;    
      //..............
     return View();
 }