Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Code solution suggested by <a href="https://stackoverflow.com/users/2984635/user2984635">https://stackoverflow.com/users/2984635/user2984635</a></p> <p>Model, index.js (unused), Animal.xml (unused) is remaining the same.</p> <p>View and controller code are updated. bellow are the updates:</p> <p><strong>VIEW</strong></p> <pre><code>@model DropDownList.Models.AnimalModels @{ ViewBag.Title = "Index"; } &lt;h2&gt;Index&lt;/h2&gt; @*&lt;script src="@Url.Content("~/Scripts/Animal/Index.js")" type="text/javascript"&gt;&lt;/script&gt;*@ @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;div&gt; &lt;fieldset&gt; &lt;div&gt;@Html.LabelFor(model =&gt; model.AnimalId)&lt;/div&gt; &lt;div&gt;@Html.DropDownListFor(model =&gt; model.AnimalId, Model.AnimalList)&lt;/div&gt; &lt;div&gt;@Html.ValidationMessageFor(model =&gt; model.AnimalId)&lt;/div&gt; //[B]the update @for (int i = 0; i &lt; Model.AnimalList.Count; i++) { @Html.HiddenFor(model=&gt;model.AnimalList[i].Value) @Html.HiddenFor(model=&gt;model.AnimalList[i].Text) } //[E]the update &lt;/fieldset&gt; &lt;input type="submit" name="Submit" value="Submit" /&gt; &lt;/div&gt; } </code></pre> <p><strong>CONTROLLER</strong></p> <pre><code>public class AnimalController : Controller { // // GET: /Animal/ public ActionResult Index() { AnimalModels model = new AnimalModels(); model = new AnimalModels(); //[B]the update model.AnimalList = new List&lt;SelectListItem&gt;(); model.AnimalList.Add(new SelectListItem { Value = "0", Text = "Tiger" }); model.AnimalList.Add(new SelectListItem { Value = "1", Text = "Lion" }); //[E]the update return View(model); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(AnimalModels model) { //[B]the update model.AnimalList[int.Parse(model.AnimalId)].Selected = true; //[E]the update return View(model); } } </code></pre>
    singulars
    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.
    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