0
I have a registration modal that I receive 2 values, I use an AJAX to save the information, however the value of @Html.DropDownList
does not go to my Controller, the strange is the value of the Description arrives in the controller.
<div class="modal-body">
<div class="form-horizontal">
@Html.ValidationSummary(true)
<div class="form-group">
@Html.Label("Descrição", new { @class = "control-label col-md-3" })
<div class="col-md-9">
@Html.TextBoxFor(model => model.Descricao, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Descricao)
</div>
</div>
<div class="form-group">
@Html.Label("Tipo de Cálculo", new { @class = "control-label col-md-3" })
<div class="col-md-9">
@Html.DropDownList("TipoCalculo")
</div><br />
</div>
</div>
</div>
<script>
$(document).ready(function () {
//$("#AjaxPost").click(function () {
//alert($('#TipoCalculo :selected').val())
$("#AjaxPost").click(function () {
var dataObject = {
Descricao: $("#Descricao").val(),
TipoCalculo: $('#TipoCalculo :selected').text(),
};
$.ajax({
url: "@Url.Action("SalvarMilestone", "Dashboard")",
type: "POST",
data: dataObject,
dataType: "json"
});
});
});
Hello, I recreated your scenario and it worked normally. How is your model class? Does it have any validation for the Tipocalculo field? How you are populating the values of the Type field?
– Bernardo Botelho
@Bernardobotelho, yes it is populating... I used the following code to see if it appeared Alert stating the value of the combo and it appears normal
$("#AjaxPost").click(function () {
 //alert($('#TipoCalculo :selected').val())
– user31040
I saw that your commented code uses val() to verify the value, but at the time of sending you used text(). The Dropbox values have text and value?
– Bernardo Botelho
Yes, it has the two
– user31040
Try putting date:{Milestone:dataObject}; to pass the data
– Janderson Thomaz