Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC 2 Filtering multiple drop down lists
    primarykey
    data
    text
    <p>I know how to approach this problem but i have very little experience dealing with anything web related.</p> <p>The situation is: I have a controller that returns a view with a user control in it. Inside the user control i have 3 drop down lists; one for companies, one for field offices and one for facilities. When the companies ddl is altered, the field office and facility ddls should change, and when the field office ddl is altered the facility ddl should change.</p> <p>Index.aspx '&lt;%@ Page Title="ManifestSearchPage" AutoEventWireup="true" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage"%></p> <p> Manifest </p> <p></p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;% using (Html.BeginForm()) { %&gt; &lt;fieldset&gt; &lt;legend&gt;&lt;h2&gt;Find a Manifest&lt;/h2&gt;&lt;/legend&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;img src="../../Content/magnify-large.jpg" width="111" height="111" align="middle"&gt;&lt;/img&gt; &lt;/td&gt; &lt;td&gt; &lt;% Html.RenderPartial("../Shared/EditorTemplates/ManifestSearch");%&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;% </code></pre> <p>} %></p> <pre><code>&lt;h2&gt;Search Results&lt;/h2&gt; &lt;div id="resultspanel"&gt; &lt;table&gt; &lt;tr&gt; &lt;/tr&gt; &lt;% foreach (var item in Model.SearchResults) { %&gt; &lt;tr&gt; &lt;td&gt; blargh &lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; &lt;/table&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p> '</p> <p>ManifestSearch.aspx ' &lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %></p> <pre><code>&lt;% using (Html.BeginForm()) {%&gt; &lt;%: Html.ValidationSummary(true) %&gt; &lt;fieldset&gt; &lt;legend&gt;Fields&lt;/legend&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.ManifestPartialId) %&gt; &lt;%: Html.CheckBoxFor(model =&gt; model.SearchByManifestPartialId)%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.SearchByManifestPartialId) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.CompanyId) %&gt; &lt;%: Html.CheckBoxFor(model =&gt; model.SearchByCompanyId)%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.SearchByCompanyId) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.TextBoxFor(model =&gt; model.ManifestPartialId) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.ManifestPartialId) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%: Html.DropDownList("CompanyId", new SelectList(ViewData["Companies"] as IEnumerable,"Id","CompanyName", Model.CompanyId))%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.CompanyId) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.FieldOfficeId) %&gt; &lt;%: Html.CheckBoxFor(model =&gt; model.SearchByFieldOfficeId)%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.SearchByFieldOfficeId) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.FacilityId) %&gt; &lt;%: Html.CheckBoxFor(model =&gt; model.SearchByFacilityId)%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.SearchByFacilityId) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.DropDownList("FieldOfficeId", new SelectList(ViewData["FieldOffices"] as IEnumerable, "Id", "FacilityName", Model.FieldOfficeId))%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.FieldOfficeId) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%: Html.DropDownList("FacilityId", new SelectList(ViewData["Facilities"] as IEnumerable, "Id", "FacilityName", Model.FacilityId))%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.FacilityId) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.SearchByDateTime) %&gt; &lt;%: Html.CheckBoxFor(model =&gt; model.SearchByDateTime) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.SearchByDateTime) %&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.FromDate) %&gt; &lt;%: Html.TextBoxFor(model =&gt; model.FromDate) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.FromDate) %&gt; &lt;/td&gt; &lt;td&gt; &lt;%: Html.LabelFor(model =&gt; model.ToDate) %&gt; &lt;%: Html.TextBoxFor(model =&gt; model.ToDate) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.ToDate) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="submit" value="Search" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;% } %&gt; </code></pre> <p>'</p> <p>This all works, with the exception of my requirement of my dropdownlists not being linked.</p> <p>I know i have to use Javascript to accomplish my requirement of related dropdownlists but i have no idea how to even approach it. Ive found some tutorials, but none seem to relate to the way i have my code set up. Can anyone help with this?</p>
    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.
    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