【发布时间】:2015-03-10 04:06:40
【问题描述】:
我有从数据库中填写的下拉列表。现在我需要在 Controller 中获取选定的值做一些操作。但没有得到这个想法。我试过的代码。
型号
public class MobileViewModel
{
public List<tbInsertMobile> MobileList;
public SelectList Vendor { get; set; }
}
控制器
public ActionResult ShowAllMobileDetails()
{
MobileViewModel MV = new MobileViewModel();
MV.MobileList = db.Usp_InsertUpdateDelete(null, "", "", null, "", 4, MergeOption.AppendOnly).ToList();
MV.Vendor = new SelectList(db.Usp_VendorList(), "VendorId", "VendorName");
return View(MV);
}
[HttpPost]
public ActionResult ShowAllMobileDetails(MobileViewModel MV)
{
string strDDLValue = ""; // Here i need the dropdownlist value
return View(MV);
}
查看
<table>
<tr>
<td>Mobile Manufacured</td>
<td>@Html.DropDownList("ddlVendor", Model.Vendor, "Select Manufacurer") </td>
</tr>
<tr>
<td>
</td>
<td>
<input id="Submit1" type="submit" value="search" />
</td>
</tr>
</table>
【问题讨论】:
-
您已将下拉列表绑定到属性
ddlVendor,但您的模型中不存在此类属性。添加属性int SelectedVendor或类似于您的模型并绑定到它。
标签: c# asp.net asp.net-mvc asp.net-mvc-4