【发布时间】:2013-12-20 21:54:14
【问题描述】:
在我的 ASP.Net 项目中,我尝试在选择行表并单击按钮后将页面重定向到其他操作。所以我有这个代码:
JQuery:
function editItem(tableId, url) {
if ($("#" + tableId + " .selected").exists()) {
var thisRowId = $("#" + tableId + " .selected").attr("id");
window.location.replace(url, { operation: "edit", carId: thisRowId });
}
};
//more code
查看(ManagementCar):
@model myProject.Model.Car.Car[]
<table class="table" id="tableCars">
<thead>
@*some code to header*@
</thead>
<tbody>
foreach (var item in Model)
{
<tr id="@(item.Id)" onclick="selectRow('tableCars', '@(item.Id)')">
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.OwnerName)
</td>
<td>
@(item.IsSold == true ? "Yes" : "No")
</td>
</tr>
}
</tbody>
</table>
<br />
<button id="btEdit" type="button" class="disable" onclick="editItem('tableCars','CarOperation')">Edit</button>
控制器:
[HttpGet]
public ActionResult CarOperation(string operation, int carId)
{
//some code...
return RedirectToAction("ManagementCar", "Backoffice");
}
但是在重定向后我有一个服务器错误,说carId 参数为空。我调试我的 jquery 并且该参数不为空。我也试过做
$.get(url, { operation: "edit", carId: thisRowId });
改为
window.location.replace(url, { operation: "edit", carId: thisRowId });
但它不会重定向。 我该如何解决这个问题?
【问题讨论】:
标签: javascript jquery asp.net redirect