Hi, I am working on this solution in asp.net MVC I have 3 models, one with customers one with customer contacts, and one with the order. I would like to make sure that after selecting the customer, a selection of contacts for that customer appears
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Ditta:</span>
</div>
@{
var listaOggetti = new List<SelectListItem>();
foreach (Cliente c in listaDitte)
{
var oggetto = new SelectListItem();
oggetto.Text = c.Nome;
oggetto.Value = "" + c.ID;
listaOggetti.Add(oggetto);
}
@Html.DropDownList("Cliente", listaOggetti, new { @class = "form-control", aria_describedby = "inputGroup-sizing-sm", name = "sel"
, @onchanghe = "aggiorna()", aria_label = "Sizing example input" })
}
</div>
<INPUT name="sel_value" value="1">
<INPUT name="sel_text" value="12">
this is how i populate the list
this is the scrip that i tryied to use
function aggiorna(sel) {
var f = document.frm;
f.sel_value.value = sel.options[sel.selectedIndex].value;
f.sel_text.value = sel.options[sel.selectedIndex].text;
}
Member
6 Points
11 Posts
Javascript problems
Sep 30, 2019 08:54 AM|jacopoFabbri|LINK
Hi, I am working on this solution in asp.net MVC I have 3 models, one with customers one with customer contacts, and one with the order. I would like to make sure that after selecting the customer, a selection of contacts for that customer appears
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Ditta:</span>
</div>
@{
var listaOggetti = new List<SelectListItem>();
foreach (Cliente c in listaDitte)
{
var oggetto = new SelectListItem();
oggetto.Text = c.Nome;
oggetto.Value = "" + c.ID;
listaOggetti.Add(oggetto);
}
@Html.DropDownList("Cliente", listaOggetti, new { @class = "form-control", aria_describedby = "inputGroup-sizing-sm", name = "sel"
, @onchanghe = "aggiorna()", aria_label = "Sizing example input" })
}
</div>
<INPUT name="sel_value" value="1">
<INPUT name="sel_text" value="12">
this is how i populate the list
this is the scrip that i tryied to use
function aggiorna(sel) {
var f = document.frm;
f.sel_value.value = sel.options[sel.selectedIndex].value;
f.sel_text.value = sel.options[sel.selectedIndex].text;
}
but nothing append
Contributor
3710 Points
1043 Posts
Re: Javascript problems
Oct 01, 2019 03:26 AM|Yongqing Yu|LINK
Hi jacopoFabbri,
According to your description, do you want to achieve cascading function between two dropdownlists?
If so,you can refer to this link for your reference:
Cascading Dropdownlist using Ajax in Asp.Net Mvc 4
This example is how to realize the cascade relationship between multiple dropdownlists in mvc.
By modifying the selection of the first dropdownlist, the data source of the second dropdownlist changes accordingly.
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
6 Points
11 Posts
Re: Javascript problems
Oct 01, 2019 08:29 AM|jacopoFabbri|LINK
thks for the answer was perfect, but there is a way for doing the same thing without using js?