我希望在ajax调用期间更改位置的值,从而节省用户手动更改值的时间,我已尝试但显然不起作用(请参阅下面的代码),任何想法哪里出错?
_CameraInfo.cshtml(局部视图)
@model JobTracker.Models.Job
<h2>Edit and Confirm</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Job</legend>
@Html.HiddenFor(model => model.JobID)
@Html.HiddenFor(model => model.OrderID)
<div class="editor-label">
@Html.LabelFor(model => model.LocationID, "Location")
</div>
<div class="editor-field">
@Html.DropDownList("LocationID", null, new {id ="Location" })
@Html.ValidationMessageFor(model => model.LocationID)
</div><br />
<div class="editor-label">
@Html.LabelFor(model => model.HighPriority)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.HighPriority, new SelectList(
new[]
{
new { Value = "Yes", Text = "Yes" },
new { Value = "No", Text = "No" },
},
"Value",
"Text",
Model
))
@Html.ValidationMessageFor(model => model.HighPriority)
</div><br />
<div class="editor-label">
@Html.LabelFor(model => model.Comments)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Comments)
@Html.ValidationMessageFor(model => model.Comments)
</div><br />
<div class="editor-label">
@Html.LabelFor(model => model.Status)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.Status, new SelectList(
new[]
{
new { Value = "In Progress", Text = "In Progress" },
new { Value = "Completed", Text = "Completed" },
new { Value = "Not Started", Text = "Not Started" },
new { Value = "Stopped", Text = "Stopped" },
},
"Value",
"Text",
Model
))
@Html.ValidationMessageFor(model => model.Status)
</div><br />
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
AJAX调用
$(document).ready(function () {
$('#qr-number').on('change', function () {
var ddl = $('#Location');
var value = "cleanroom";
$.ajax({
type: "Get",
url: '/CameraInfo/Edit',
data: { ID: $('#qr-number').val() },
success: function (response) {
ddl.val(value);
$('#Sample').html(response);
},
error: function (response) {
if (response.responseText != "") {
alert(response.responseText);
alert("Some thing wrong..");
}
}
});
});
});
});
顺便说一下,DDL由模型数据填充。
我认为它在成功期间由于某种原因没有改变,也许是因为视图没有完全加载?
如果您需要任何进一步的信息,请与我们联系:)
答案 0 :(得分:1)
要检查的事情。确保渲染下拉列表中的ID为Location。一些帮助程序将覆盖该更改。接下来请确保您的下拉列表中有一个值为“cleanroom”的选项。如果您尝试按文字设置,请参阅Here