Hi.I am new here.I know little angular,asp.net mvc ,jquery,json but cannot use them and combine in one project.So I have dropdown list-contry,trans Name,vagon Name.I want choose trainsName,after that find in database count Vagon of this choosen Train.And show dropdown list this vagon.
As I understand I need to pass from View to Controller which train is choosen,then find from database CountVagon(for example Train-T0000000023 has 5 vagon) And pass from Controller to View DropdownList(which consist-Vagon1,Vagon2,Vagon3,Vagon4,Vagon5).
Please explain me,if somebody can solve that.I have searched many time but couldnt do exatly what I wanted.Thank you :))
What I have tried:
<script type="text/javascript">
$(document).ready(function () {
$('#Name').change(function () {
var TrainID= $('#Name :selected').val();
});
});
</script>
<h2>Buy</h2>
<div class="table table-bordered">
<div class="filter">
@Html.DropDownListFor(x => x.City, (SelectList)ViewBag.TrainsCity)
@Html.DropDownListFor(x => x.Name, (SelectList)ViewBag.TrainsName)
@Html.DropDownListFor(x => x.VagonCount, (List<SelectListItem>)ViewBag.TrainsVagon)
</div>
ANd Controller
public ActionResult Buy()
{
ViewBag.TrainsName = new SelectList(db.Trains, "ID", "Name");
ViewBag.TrainsCity = new SelectList(db.Trains, "ID", "City");
ViewBag.TrainsVagon = PopulateCountVaqon(7);
PopulateCountVaqon(7);
IEnumerable<TrainReqistration.Models.Train> trains = db.Trains;
return View();
}
List<SelectListItem> PopulateCountVaqon(int count)
{
List<SelectListItem> countVagon = new List<SelectListItem>();
for(int i = 0; i <= count; i++)
{
countVagon.Add(new SelectListItem() { Value = i.ToString(), Text = "Vaqon " + i });
}
return countVagon;
}