您好我正在一个应用程序中工作,我正在使用json调用拒绝请求。 现在,当我要逐一拒绝请求时,我发现一个问题在单页上当我拒绝一个请求时它会被拒绝但是当我要拒绝第二个请求时它不会拒绝该请求。
如果在这种情况下我需要拒绝第二个请求,我需要刷新该页面,然后我能够拒绝第二个请求。
以下是截图
我的观看页码。
在脚本代码中
function declinestudentrequest() {
var StudentRequestId = document.getElementById('hdstatusstudentrequestid').value;
var StatusId = document.getElementById('hdstatusdecline').value;
$.ajax({
url: '/Account/declinestudentrequest',
type: 'GET', // You can use GET
data: { 'StudentRequestId': StudentRequestId },
dataType: "json",
context: this,
cache: false,
success: function (data) {
if (data == "Success") {
$("#GetStatusMessage_" + StudentRequestId).css({ "display": "block" });
$('#div_p_' + StudentRequestId).text("You have decline for student Response");
$("#GetReqdec_" + StudentRequestId).hide();
}
else { alert('Some Error'); }
},
error: function (request) {
console.log(request);
}
});
}
设计
@if (Convert.ToInt16(item.StatusId) == 1)
{
<div id="GetStatusMessage_@item.StudentRequestId" style="display:none;">
<p id="div_p_@item.StudentRequestId">Waiting for student Response.</p>
</div>
<div id="GetReqdec_@item.StudentRequestId">
@using (Html.BeginForm("TutorDashboard", "AccountController"))
{
@Html.TextAreaFor(model => item.Description, new { @class = "form-control", @placeholder = "Please describe how you can help.", @id = "txtdescription" })
<br />
<span>Hourly rate :</span>
@Html.EditorFor(model => item.Ratedummy, new
{
htmlAttributes = new { @class = "form-control", placeholder = "Price", maxlength = 10, id = "txtrate" }
})
<p class="text-right">
<input type="hidden" id="hdstatusrequest" name="hdstatusrequest" value='2' />
<input type="hidden" id="hdstatusdecline" name="hdstatusdecline" value='3' />
<input type="hidden" id="hdstatusstudentrequestid" name="hdstatusstudentrequestid" value='@item.StudentRequestId' />
<input type="button" onclick="return declinestudentrequest();" class="btn btn-default btn-hire decline_btn" value="Decline" />
</p>
}
</div>
}
我的帐户控制器侧码
public ActionResult declinestudentrequest(string StudentRequestId)
{
string result = "";
try
{
if (User.Identity.IsAuthenticated)
{
TutorStudentRequest tsr = new TutorStudentRequest();
tsr.StudentRequestId = Convert.ToInt32(StudentRequestId);
tsr.Rate = 0;
tsr.StatusId = 3;
db.TutorStudentRequests.Add(tsr);
db.SaveChanges();
result = "Success";
}
else
{
return RedirectToAction("Index", "Home");
}
}
catch (Exception ex)
{
result = "Error";
throw ex;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
为什么我的第二次拒绝请求无效?
答案 0 :(得分:0)
这个问题已经解决,因为有一个id出现冲突的问题所以我尝试了类似的事情。
在视图页面上,我进行了更改
<input type="hidden" id="hdstatusstudentrequestid_@item.StudentRequestId" name="hdstatusstudentrequestid" value='@item.StudentRequestId' />
<input type="button" onclick="return declinestudentrequest('@item.StudentRequestId');" class="btn btn-default btn-hire decline_btn" value="Decline" />
和脚本
function declinestudentrequest(id) {
var StudentRequestId = document.getElementById('hdstatusstudentrequestid_'+id).value;
var StatusId = document.getElementById('hdstatusdecline').value;
$.ajax({
url: '/Account/declinestudentrequest',
type: 'GET', // You can use GET
data: { 'StudentRequestId': StudentRequestId },
dataType: "json",
context: this,
cache: false,
success: function (data) {
if (data == "Success") {
$("#GetStatusMessage_" + StudentRequestId).css({ "display": "block" });
$('#div_p_' + StudentRequestId).text("You have decline for student Response");
$("#GetReqdec_" + StudentRequestId).hide();
}
else { alert('Some Error'); }
},
error: function (request) {
console.log(request);
}
});
}
在这里,我通过将studentrequestid作为唯一的
传递出独特性