我正在ASP.NET MVC3上構建文檔管理系統的網站,在頁面中我使用的是局部視圖,局部視圖表示一個簡單的Form.There有一個下拉列表,當選擇一個選項時,所選選項的ID應該轉到操作Result。爲此,我使用$ .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 2012-07-16 08:23:06
感謝BuildStarted。它工作時,我改變我的JSON。再次感謝你..... – Krishan 2012-07-16 08:51:24