Note that there are some explanatory texts on larger screens.

plurals
  1. POnot able to get values in second dropdownlist in a view
    text
    copied!<p>I have got cascaded dropdown list to show items in second drop downlists regarding the selected ones in first drop downlist for that purpose I have done like this.... code for Controller</p> <pre><code>namespace MvcSampleApplication.Controllers { public class CascadeListController : Controller { public ActionResult Index() { List&lt;SelectListItem&gt; state = new List&lt;SelectListItem&gt;(); state.Add(new SelectListItem { Text = "State1", Value = "State1" }); state.Add(new SelectListItem { Text = "State2", Value = "State2" }); ViewBag.StateName = new SelectList(state, "Value", "Text"); return View("BasicDrop"); } public JsonResult Districtlist(string Id) { var districttype = from s in CascadingDropdowns.GetDistrictList() where s.StateName == Id select s; return Json(new SelectList(districttype.ToArray(), "StateName", "DistrictName"), JsonRequestBehavior.AllowGet); } } } </code></pre> <p>and this is for view </p> <pre><code>@Scripts.Render("~/bundles/jquery") &lt;script type="text/javascript"&gt; $(function () { $("State").change(function () { $.getJSON('/CascadeListController/Districtlist' + $('#State').val(), function (data) { var items = '&lt;option&gt;Select a District&lt;/option&gt;'; $.each(data, function (i, districttype) { items += "&lt;option value = '" + districttype.Value + "'&gt;" + districttype.Text + " &lt;/option&gt; "; }); $('#District').html(items); }); }); }); &lt;/script&gt; @model MvcSampleApplication.Models.CascadingDropdowns @{ ViewBag.Title = "BasicDrop"; } &lt;h2&gt;BasicDrop&lt;/h2&gt; @using (Html.BeginForm()) { &lt;div&gt; &lt;fieldset&gt; &lt;legend&gt;DropDownlists&lt;/legend&gt; @Html.Label("State") @Html.DropDownList("State", ViewBag.StateName as SelectList,"Select A state", new {id= "State"}) @Html.Label("District"); &lt;div class="mycombo"&gt; &lt;select id ="District" name ="Distrct"&gt;&lt;/select&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt; } </code></pre> <p>when i select the item in first drop down list I am not able to see any items in second one and i have used the div property for second dropdown list for increasing the width i have specified width like '70px' but it also does not work..</p> <p>Would any one pls give any suggestions on this one... Many Thanks in advance.</p>
 

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