Since you marked your question as MVC, you could be using Model binding in your View with:
@model SomePOCOModel
And then use:
@Html.DropDownListFor(x => Model.UserTableId1, Model.UserTable),
"--Select User--",
new { @class = "btn btn-primary" })
@Html.DropDownListFor(x => Model.UserTableId2, Model.UserTable),
"--Select User--",
new { @class = "btn btn-primary" })
When loading your View pass the Model:
public ActionResult Index()
{
SomePOCOModel myModel = new SomePOCOModel();
//Set the property UserTable to an IEnumerable<SelectListItem>
//built using your DB user table
return View("Index", myModel);
}
And your View Model:
public class SomePOCOModel()
{
public int UserTableId1 {get; set;}
public int UserTableId2 {get; set;}
public IEnumerable<SelectListItem> UserTable {get; set;}
}
And finally your controller post method, change to accept the model type
bound to your View:
//Accept the model type bound to your View
[HttpPost]
[ValidateAntiForgeryToken] //Use this if placing an antiforgery token in your form
public ActionResult ShowAllDetail(SomePOCOModel myModel)
{
//Do something with the drop down selections
//myModel.UserTableId1
//myModel.UserTableId2
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…