我在ASP.NET MVC3上为文档管理系统构建一个网站,在我使用局部视图的页面中,部分视图表示一个简单的表单。下拉列表,选择一个选项时选定选项的ID应该采取行动结果。为此,我使用$.getJSON方法将值传递给操作方法。但问题是 ID 不会转到 ActionResult。谁能帮我解决这个问题?
cshtml代码
<div >
@using (Html.BeginForm("GetFilteredActivityLogs", "Document", FormMethod.Post, new
{
id = "activityLog",
@class = "form-horizontal",
}))
{
<h3>Activity Log</h3>
<div>
<div style="float: left" class="control-label">
<label>
Action Type
</label>
</div>
<div class="controls">
@Html.DropDownListFor(model => model.SelectedActionId, Model.ActionTypes as SelectList, "All", new {
id = "SelectedActionId"
})
</div>
<table class="table table-bordered" style="margin-top: 20px; width: 100%;">
<thead>
<tr>
<th style="width: 15%; text-align: center">
Employee No
</th>
<th style="width: 20%; text-align: center">
Employee Name
</th>
<th style="width: 45%; text-align: center">
Action
</th>
<th style="width: 20%; text-align: center">
Date and Time
</th>
</tr>
</thead>
<tbody id="Activities">
</tbody>
</table>
</div>
}
</div>
控制器:
public ActionResult GetFilteredActivityLogs(int actionTypeId)
{
return View();
}
脚本:
<script type="text/javascript">
$(function ()
{
$('#SelectedActionId').change(function ()
{
var selectedActivityId = $(this).val();
$.getJSON('@Url.Action("GetFilteredActivityLogs", "Document")', { activityId: selectedActivityId }, function (FilteredActivities)
{
var ActivitySelect = $('#Activities');
// GroupSelect.empty();
$.each(FilteredActivities, function (index, activity)
{
// some code goes here...
});
});
});
});
</script>