這是我的cshtml代碼和我的jQuery,我試過這兩種不同的方式。當我點擊我的按鈕批准,我希望它去帶參數的行動ApprovePoints,但沒有任何反應爲什麼我的回發不工作Html.Actionlink甚至按鈕JQuery
這裏是我的控制器:
[HttpGet]
public ActionResult ApprovePoints()
{
// Build out the Screen to Approve Points
var model = new AdminPointsViewModel();
var ptsToApprove = from x in db.CommunityPts
join y in db.CertPointTypes on x.TypeId equals y.TypeId
where x.Pending == true
select new AdminPoints
{
communityId = x.Community.CommunityId,
communityName = x.Community.ComunityName,
pointId = x.CertPoint.PointId,
pointDesc = x.CertPoint.PointDescription,
typeId = x.CertPoint.TypeId,
typeDesc = y.TypeName,
pointsExpected = x.CertPoint.Points,
pointsEarned = (int) x.PointsEarned,
dateApplied = (DateTime) x.DateApplied,
};
model.adminPoints = ptsToApprove;
return View(model);
}
[HttpPost]
public ActionResult ApprovePoints(int cid, int pid)
{
var approvePts = db.CommunityPts.Where(x => x.CommunityId == cid && x.PointId == pid).SingleOrDefault();
return View();
}
}
這裏是標記和jQuery的:
<form method="post">
<table border="1" style="border-color:white; border-width:thick;">
<thead style="font-weight:bold">
<tr>
<th>Community</th>
<th>Activity</th>
<th>Category Code</th>
<th>Points Expected</th>
<th>Points Earned</th>
<th>Date Applied</th>
<th>Approve</th>
</tr>
</thead>
@if (Model.adminPoints != null)
{
foreach (var pts in @Model.adminPoints)
{
<tr>
<td>@pts.communityName</td>
<td>@pts.pointDesc</td>
<td>@pts.typeDesc</td>
<td>@pts.pointsExpected</td>
<td>@pts.pointsEarned</td>
<td>@Convert.ToDateTime(@pts.dateApplied).ToString("MM/dd/yyyy")</td>
<td>@Html.ActionLink("Approve Points", "ApprovePoints", "Admin", new {cid= @pts.communityId, pid = @pts.pointId}, new {@class = "btn btn-default"})</td>
<td><a href="#" class="btn btn-default" onclick="ApprovePoints(@pts.communityId, @pts.pointId);">Approve Points</a></td>
</tr>
}
}
else
{
<tr>
<td>There are no points to approve at this time.</td>
</tr>
}
<tfoot>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tfoot>
</table>
</form>
<script>
var ApprovePoints = (function (CommunityId, PointId) {
var data = new FormData();
data.append("id", CommunityId);
data.append("pid", PointId);
alert(data.get("id"));
alert(data.get("pid"));
$.ajax({
type: "POST",
url: "/Admin/ApprovePoints/",
data: data,
processData: false,
success: function() {
window.location.href = "/Admin/ApprovePoints/"
},
error: function (errorData) { alert(errorData); }
});
});
</script>
是什麼點如果你沒有做任何事情,將參數傳遞給你的發佈行動?您對數據庫執行查詢,但是您不使用查詢的結果並始終返回相同的視圖。 – CodingYoshi