Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing Values from the SelectList Items Using ViewModel
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/OF23Q.png" alt="enter image description here"></p> <p>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:</p> <pre><code>public ActionResult UploadDoc(IEnumerable&lt;HttpPostedFileBase&gt; files) { foreach (var file in files) { if (file != null &amp;&amp; file.ContentLength &gt; 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"); } </code></pre> <p>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.</p> <pre><code>&lt;form action="UploadDoc" method="post" enctype="multipart/form-data"&gt; &lt;table id="tblUploadDocs"&gt; &lt;tr id="row1"&gt; &lt;td&gt;&lt;input type="file" name="files" id="file1" /&gt;&lt;/td&gt; &lt;td&gt;Bu dilden&lt;/td&gt; &lt;td&gt;@Html.DropDownList("ddlFromLanguage1", ViewBag.Languages as SelectList)&lt;/td&gt; &lt;td&gt;şu dile çevrilecek&lt;/td&gt; &lt;td&gt;@Html.DropDownList("ddlToLanguage1", ViewBag.Languages as SelectList)&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;a href="javascript:addRow();" style="margin:10px 0;"&gt;Yeni dosya ekleyin&lt;/a&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload