Dzień dobry
mam sytuacje gdy obsługa DropDownList przestaje mi działać, gdy wartość ustawianą zmieniam, z pola należącego do obiektu model view , na wywołanie obiekt.pole, który to obiekt też jest częścią obiektu model view
po zmianie DropDownList ustawia wartości poprawnie obiekt.pole jednak poniższy kod w javascript obsługujący modyfikację powiązanych pól przestaje działać, chodzi tu zapewne o zapis w kodzie javascript
modyfikuje w kodzie przy pomocy DropDownList, id magazynu, a javascript aktualizuje pola nr magazynu i jego nazwę
pytanie jak zapisać odwołanie do obiekt.pole w kodzie javascript
kod który działa
@model HurtowniaWebMVC.DokumentPzViewModel
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@section Scripts {
<script type="text/javascript">
$(function(){
$("#wybranyMagazynId").change(function() {
var t = $(this).val();
if (t !== "") {
$.post("@Url.Action("daneMagazynu", "Home")?val=" + t, function(res) {
if (res.Success === "true") {
//enable the text boxes and set the value
$("#nrMagazynu").prop('disabled', false).val(res.Data.nrMagazynu);
$("#nazwaMagazynu").prop('disabled', false).val(res.Data.nazwaMagazynu);
} else {
alert("Error getting data!");
}
});
} else {
//Let's clear the values and disable :)
$("input.editableItems").val('').prop('disabled', true);
}
});
});
</script>
}
<div class="form-horizontal">
<h4>DokumentPzNaglowekDTO</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(m => m.testId)
<div class="form-group">
@Html.Label("Magazyny wybór", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(m => m.wybranyMagazynId, new SelectList(Model.MagazynyDTO, "idMagazynu", "nazwaMagazynu"), Model.wybranyMagazynId)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.nrMagazynu, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.nrMagazynu, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nrMagazynu, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.nazwaMagazynu, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.nazwaMagazynu, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nazwaMagazynu, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
kod który odwołuje się do obiekt.pole czyli NaglowekPzDTO.idMagazynu, DropDownList ustawia dobrze wartość tylko kod javascript nie widzi zmiany wartości pola tego obiektu
chodzi tu pewnie o zapis tylko jaki ? samo idMagazynu też nie działa
$("#NaglowekPzDTO.idMagazynu").change(function() {
@model HurtowniaWebMVC.DokumentPzViewModel
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@section Scripts {
<script type="text/javascript">
$(function(){
$("#NaglowekPzDTO.idMagazynu").change(function() {
var t = $(this).val();
if (t !== "") {
$.post("@Url.Action("daneMagazynu", "Home")?val=" + t, function(res) {
if (res.Success === "true") {
//enable the text boxes and set the value
$("#nrMagazynu").prop('disabled', false).val(res.Data.nrMagazynu);
$("#nazwaMagazynu").prop('disabled', false).val(res.Data.nazwaMagazynu);
} else {
alert("Error getting data!");
}
});
} else {
//Let's clear the values and disable :)
$("input.editableItems").val('').prop('disabled', true);
}
});
});
});
</script>
}
<div class="form-horizontal">
<h4>DokumentPzNaglowekDTO</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(m => m.testId)
<div class="form-group">
@Html.Label("Magazyny wybór", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.NaglowekPzDTO.idMagazynu, new SelectList(Model.MagazynyDTO, "idMagazynu", "nazwaMagazynu"), Model.NaglowekPzDTO.idMagazynu)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.nrMagazynu, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.nrMagazynu, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nrMagazynu, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.nazwaMagazynu, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.nazwaMagazynu, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nazwaMagazynu, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>