我只是想在更改dropdownlist時更改文本框的值,可以告訴我發生了什麼問題嗎?我在我的控制器真正的新jQuery中在更改下拉列表時更改文本框的值
代碼僅僅是一個樣品後,我的代碼工作
查看
<script type="text/javascript">
$(document).ready(function() {
$("#ddltype").change(function() {
var id = $(this).val();
$.getJSON("@Url.Action("getWeightedAverage", "Employee")", { id: id }, function (Ave) {
$("#Average").val(Ave);
});
});
});
</script>
<fieldset>
<legend>Grade</legend>
<div class="editor-label">
@Html.DropDownListFor(model => model.g_type, new List<SelectListItem>{
new SelectListItem {Value = "1", Text = "Written Work"},
new SelectListItem {Value = "2", Text = "Performance Task"},
new SelectListItem {Value = "3", Text = "Quarterly Assesment"},
}, new {id = "ddltype" })
@Html.ValidationMessageFor(model => model.g_type)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.weighted_percent)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.weighted_percent, new { id = "Average" })
@Html.ValidationMessageFor(model => model.weighted_percent)
</div>
控制器我會做更多的
public JsonResult getWeightedAverage(string id)
{
string Ave = "40";
return Json(Ave, JsonRequestBehavior.AllowGet);
}
爲什麼'這個描述。平均',只是'$(「#平均」)。val(平均);'會工作。 –
仍然不能正常工作:( – Renz