我试图在MVC dropdownlist中实现等价的change事件,它将使用数据库中的相关数据填充下表。使用Dropwdownlists填充HTML表格MVC中的更改事件
但是我的Ajax调用没有触发控制器操作方法。有谁能够告诉我在哪里,我错了
查看和vavascript
@model WebArtSampler.Models.AssignRequestModel
@{
ViewBag.Title = "AssignRequest";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>AssignRequest</h2>
@using (Html.BeginForm("AssignRequestNew", "SamCutAssignmentMasters"))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.CutAssignID)
<div class="form-group">
@Html.LabelFor(model => model.CutAssignID, "Cutting Request #", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*@Html.DropDownListFor(model => model.CutAssignID, (SelectList)ViewBag.CutAssignID, "--Select One--", htmlAttributes: new { @class = "form-control" })*@
@Html.DropDownList("Id", (SelectList)ViewBag.CutAssignID, htmlAttributes: new { @class = "form-control" })
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<div id="div1">
<table class="table">
<tr>
<th>
Req#
</th>
<th>
Buyer
</th>
<th>
Pattern Ref#
</th>
<th>
Style
</th>
<th>
Style Description
</th>
<th>
Fabric
</th>
</tr>
@foreach (var student in Model.Reqnumlist)
{
<tr>
<td>
@student.ReqNum
</td>
<td>
@student.BuyerName
</td>
<td>
@student.PatterRefNum
</td>
<td>
@student.StyleName
</td>
<td>
@student.StyleDescription
</td>
<td>
@student.Fabric
</td>
</tr>
}
</table>
</div>
JQuery的我用的是
<script type="text/javascript">
$(document).ready(function() {
debugger;
$("#Id").change(function() {
debugger
var Id = $(this).find('option:selected').val();
$.ajax({
url: "@Url.Action("PopulateDetails","SamCutAssignmentMasters")",
type: 'Get',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: { 'Id': Id },
success: function (data) {
if (data.success) {
debugger
document.getElementById("ProductName").value = data.productName;
}
else {
alert('invalid ID' + data.success);
}
}
});
});
});
</script>
型号
public class SamCutAssignmentMastersController : Controller
{
[HttpGet]
public JsonResult PopulateDetails(int id)
{
return Json(GetDetailsofaspecificTicket(id));
}
}
确定下拉列表ID的ID?如果我希望它与模型名称不同,我通常必须将其设置为html属性,例如:'{@class =“form-control”,id =“Id”}' – Pete
在调整内是否存在“调试器”事件受到下拉改变? –