I am new to MVC.NET 5; I am developing an application with dropdowns and forms. My dropdowns are created my model and I cant fugure out how to take the falues from the dropdowns. Here is part of the code:
first dropdown partial view:
@using System.Data.SqlClient
@model Cars.Web.Models.TestModel
@using (Ajax.BeginForm("GetByMake", "Cars", null, new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "models",
InsertionMode = InsertionMode.Replace
}, new { id = "selectMarke" }))
{
@Html.DropDownListFor(
m => m.SelectedMarkeId,
new SelectList(Model.Markes, "Id", "Name"),
String.Empty
)
}
<script>
$('#SelectedMarkeId').change(function () {
console.log("asd");
$('#selectMarke').submit();
});
</script>
here is the second:
@model Cars.Web.Models.TestModel
@if (Model.Models != null && Model.Models.Any())
{
@Html.DropDownList(
"models",
new SelectList(Model.Models, "Id", "ModelName"),
string.Empty
)
}
I can pass from the firstone the id to the second one form the controller, but I think, that is not the right way. I wonder if I add more forms, how to bind them with this two drop down on submit. Thanks