I use in my Razor View the following ViewModel.
public class EditionStatusReservation
{
public Reservation Reservation { get; set; }
[Display(Name = "Status:")]
public IEnumerable<SelectListItem> States { get; set; }
}
The class Reservation looks like this:
public class Reservation
{
[Display(Name = "Status:")]
[Required]
[MinLength(3), MaxLength(15)]
public string Status { get; set; }
}
In my Razor view when I click submit button I would like to assign to variable Status
new value using javascript. So far I created something like this.
$(function () {
$("form").submit(function () {
var selTypeText = $('select[name="SelectReservationState"]').val();
$("#Reservation.Status").val(selTypeText);
});
});
This solution is not proper. How can I access to field named Status
to set its value?
Section with dropdownlist where item to assign is taken.
<div class="form-group">
@Html.LabelFor(model => model.States, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("SelectReservationState", Model.States, new { id = "SelectReservationState" })
</div>
</div>