0
我有combobox在视图中,我需要在组合框中获取选择值。需要从DropDownListFor获得价值asp.net mvc
代码视图:
@Html.DropDownListFor(model => model.servicesModel, (SelectList)ViewBag.serviceNames, new { @id = "listNames" })
,在组合框中添加值(我知道,我错过了在数据库中的符号创建表时)
代码行动:
var servicesDetails = dbModel.SERVICES.ToList();
ViewBag.serviceNames = new SelectList(servicesDetails, "iIdSevices", "vName");
我有形式,按按钮,之后,由于@using (Html.BeginForm("SendApplication", "Home", FormMethod.Post))
我发送数据到我的actionResult。
我的ActionResult:
[HttpPost]
public ActionResult SendApplication(App_AppTemp_Serv_PersInfModel appFile, int iIdServices)
{
int iIdService = 0;
var serviceDetails = dbModel.SERVICES.Where(x => x.iIdSevices == iIdServices).FirstOrDefault();
iIdService = serviceDetails.iIdSevices;
if (bFile == true)
{
appFile.appModel.vFile = "Приклепленные файлы имеются";
}
else
{
appFile.appModel.vFile = "Приклепленных файлов нет";
}
appFile.appModel.vDate = Convert.ToString(DateTime.Now);
try
{
dbModel.APPLICATIONS.Add(appFile.appModel);
dbModel.SaveChanges();
ModelState.Clear();
}
catch (Exception exc)
{
ViewBag.sErrorMessage = exc.Message;
}
return View("~/Views/Home/ProblemForm.cshtml", appFile);
}
但我无法摆脱组合框的数据,我不知道如何?也许使用类和获得类价值,任何人都有这个想法?