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);
}
但我無法擺脫組合框的數據,我不知道如何?也許使用類和獲得類價值,任何人都有這個想法?