I have some comboboxes on form, like this:
@Html.DropDownListFor(x => x.ComboId, Model.ComboValues)
Also, I have simple action method, which returns recieved model in same view. When change selected item, and submit form, I'll get same page with correct selected value in combobox. But when I click "Back" button in my browser (check this in Chrome 25+, IE 9+), I'll get last selected value.
For example , let ComboValues
contains 2 values: 1
and 2
. Previously, ComboId = 1
. When I change it to 2
and submit, I'll have form with correct value 2
. But when I click "Back" button in browser, I'll still have combobox with value 2
(but I was hope to see 1
).
This behavior occurs, because I don't call action, when "Back" in browser. And my page wasn't redrwaing. We can fix this behavior with recalcaluting combobox selected item when page loaded:
$(function () {
$("#@Html.IdFor(m => m.ComboId)").val("@Model.ComboId");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.