【发布时间】:2012-07-16 07:49:21
【问题描述】:
I am building a Website for document management system on ASP.NET MVC3, in a page I am using a Partial view, the Partial View represents a simple Form.There is a drop down list and when one option is selected the 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>
【问题讨论】:
-
尝试将您的 json 从
{ activityId: selectedActivityId }更改为{ actionTypeId: selectedActivityId }。您的视图需要一个传递的参数,但您没有发送具有该名称的参数。 -
感谢 BuildStarted 。当我改变我的json时它起作用了。再次感谢您.....
标签: jquery asp.net-mvc-3