I have reservation form where values from one select tab depend on values from other select tab.
On change of value in one tab ajax is called and sends model to controller without submiting form.
In controller action i cant get @Model value.
What can i do to fix it?
(code works only need to get value of @Model to action in controller)
Thanks for trying to help!!
Here is my form
<div class="row">
<div class="col-md-12 form-group">
<label asp-for="poslovnice">Odabir poslovnice</label>
<select asp-for="PoslovnicaID" asp-items="Model.poslovnice" class="form-control ">
<option selected disabled>Odabir poslovnice</option>
</select>
<span asp-validation-for="PoslovnicaID" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label asp-for="Ime">Ime</label>
<input type="text" class="form-control" asp-for="Ime">
<span asp-validation-for="Ime" class="text-danger"></span>
</div>
<div class="col-md-6 form-group">
<label asp-for="Prezime">Prezime</label>
<input type="text" class="form-control" asp-for="Prezime">
<span asp-validation-for="Prezime" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label asp-for="Email">Email</label>
<input type="email" class="form-control" asp-for="Email">
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label asp-for="brojOsoba">Broj osoba</label>
<select asp-for="brojOsobaID" asp-items="Model.brojOsoba" class="form-control">
<option selected disabled>Odabir</option>
</select>
<span asp-validation-for="brojOsobaID" class="text-danger"></span>
</div>
<div class="col-md-6 form-group">
<label asp-for="BrojTelefona">Telefon</label>
<input type="text" class="form-control" asp-for="BrojTelefona">
<span asp-validation-for="BrojTelefona" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label asp-for="DatumRezervacije">Datum rezervacije</label>
<input type="date" class="form-control" asp-for="DatumRezervacije" onkeypress="return false;">
<span asp-validation-for="DatumRezervacije" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label asp-for="TerminRezervacije">Termin</label>
<select asp-for="TerminRezervacijeID" asp-items="Model.TerminRezervacije" class="form-control">
<option selected disabled>Termin</option>
</select>
<span asp-validation-for="TerminRezervacijeID" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<label asp-for="Napomena">Message</label>
<textarea class="form-control" asp-for="Napomena" cols="30" rows="7"></textarea>
<span asp-validation-for="Napomena" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="col-md-12 form-group">
<input type="submit" class="btn btn-primary btn-lg btn-block" value="Reserve Now" data-save="modal">
</div>
</div>
</form>
my js code
<script>
$("select, #DatumRezervacije").change(function () {
//window.alert("aa");
$.get("/Rezervacija/RezervacijaPartial?mod=@Model", function (data) {
$("#rezervacijaPlaceholder").html(data)
})
})
and my controller action
public IActionResult RezervacijaPartial(RezervacijaVM mod)
{
RezervacijaVM model = new RezervacijaVM();
//logic
return PartialView(model);
}
question from:
https://stackoverflow.com/questions/65660710/send-model-from-view-to-controller-with-ajax 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…