0
I got this dropdown
<div class="form-group">
@Html.Label("Grupo de Desconto", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("GrupoDescontos", new SelectList(ViewBag.Desconto, "Id", "Descricao"), new { @id = "GrupoDescontos", @class = "Makewide" })
@*@Html.ValidationMessageFor(model => model.HomeTemplateId, "", new { @class = "text-danger" })*@
</div>
</div>
Whenever I select an ID on the list screen and when I enter the Detail screen, the ID=1 option is selected, even if I have selected Section 3, for example. How do I leave selected in Dropdown the corresponding ID item?
EDIT1
This is cshtml with the dropdown list that is called by index and then by Dropdown
<div>
<h4></h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.Label("Grupo de Desconto", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("GrupoDescontos", new SelectList(ViewBag.Desconto, "Id", "Descricao"), new { @id = "GrupoDescontos", @class = "Makewide" })
@*@Html.ValidationMessageFor(model => model.HomeTemplateId, "", new { @class = "text-danger" })*@
</div>
</div>
</div>
<div id="GridPartial"></div>
@Html.Partial("DetailsPartial")
<p>
@Html.ActionLink("Back to List", "Index")
</p>
<script type="text/javascript">
$(document).ready(function () {
$("#GrupoDescontos").change(function () {
$.ajax
({
url: '' + $(this).val(),
type: 'GET',
success: function (dados) {
$("#GridPartial").empty();
$("#GridPartial").html(dados);
//var resultado = dados;
},
error: function (erro) {
alert("erro");
}
});
});
});
$(document).ready(function () {
$("#GrupoDescontos").val();
});
</script>
Since there was no cshtml before I made an example by putting jquery to run in a $( Document ).ready, but you are using ajax, if it is after his call you want change you can make the call in ajax Success.
– George Wurthmann