I'd like to get the values of the selected items in dropdownlists. I am saving the files into the database with the following code:
public ActionResult UploadDoc(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
if (file != null && file.ContentLength > 0)
{
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
Document doc = new Document
{
UploadedOn = DateTime.Now,
MimeType = file.ContentType,
UserName = User.Identity.Name,
Data = data,
FromLanguage = 1,
ToLanguage = 2
};
dbContext = new MedicalDb();
dbContext.Documents.Add(doc);
dbContext.SaveChanges();
}
}
return RedirectToAction("Index");
}
but, I'd also like to get the selected values from the dropdownlists so that I can populate the FromLanguage and ToLanguage properties of the documents. I guess I'd need a viewmodel, but don't know how to do it. New rows for document upload are added using jQuery and names of the ddls are "ddlFromLanguage1", "ddlFromLanguage2", "ddFromLanguage3", and "ddlToLanguage1", "ddlToLanguage2", "ddlToLanguage3", etc. Thanks in advance for any help.
<form action="UploadDoc" method="post" enctype="multipart/form-data">
<table id="tblUploadDocs">
<tr id="row1">
<td><input type="file" name="files" id="file1" /></td>
<td>Bu dilden</td>
<td>@Html.DropDownList("ddlFromLanguage1", ViewBag.Languages as SelectList)</td>
<td>şu dile çevrilecek</td>
<td>@Html.DropDownList("ddlToLanguage1", ViewBag.Languages as SelectList)</td>
</tr>
</table>
<br />
<a href="javascript:addRow();" style="margin:10px 0;">Yeni dosya ekleyin</a>
<input type="submit" />
</form>