私はMVCドロップダウンリストに相当する変更イベントを実装しようとしていましたが、データベースのrelavantデータで下の表を埋めます。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
'debugger'を変更しますか?イベントはドロップダウンの変更でヒットしますか? –