Form contains two dropdown lists created using code below.
Both dropdown list elements have property Alusdok.
If item in first dropdown is selected, second dropdown should show only those items whose Alusdok
properties have same aluses as in first dropdown selected item Alusdok property.
Both list are small, contain 1-30 elements. Which is best UI for this?
How to implement this, can some jQuery magic applied or other idea ?
<%= Html.DropDownList("_Report", Model.Reports, new { size = 10 })%>
<%= Html.DropDownList("_Paring", Model.Parings, new { size = 10 })%>
viewmodel:
public class ReportViewModel : ViewModelBase
{
public List<SelectListItem> Reports { get; set; }
public string _Report { get; set; }
public List<SelectListItem> Parings { get; set; }
public string _Paring { get; set; }
public ReportViewModel() {
...
Reports = new List<SelectListItem>();
foreach (ReportElem r in GetReportList())
Reports.Add(new SelectListItem { Text = r.Nimetus, Value = r.Alusdok + r.Jrk.ToString() });
Parings = new List<SelectListItem>();
foreach (ParingElem p in GetParings())
Parings.Add(new SelectListItem { Text= p.DisplayName, Value= p.Id.ToString() });
}
}
public class ReportElem {
public string Nimetus,Alusdok;
public int Jrk;
}
public class ParingElem {
public string DisplayName, Alusdok;
public int Id;
}
I’m using ASP.NET MVC2 , jQuery, jQueryUI
You could create an action that accepts a
ReportElem.Alusdokvalue and returns a JSON list ofParingElemobjects.Then, you could use jQuery to call this action and populate your second dropdown list. It looks like your dropdowns have id’s:
_Reportand_Paring, so I assume that below.Keep in mind you might need to modify your routing (probably in global.asax) to accept requests of the form
/ControllerName/GetParingElems/{parentAlusdok}. You may also need to tweak theurlargument of the$.ajaxcall if your action resides in another controller, etc.