【发布时间】:2016-07-19 06:20:35
【问题描述】:
我使用 ASP.Net MVC5 创建新闻站点。每个新闻都有喜欢和不喜欢。
我使用 Ajax 和 Json 禁止刷新页面。
但是当我点击喜欢或不喜欢时,显示此错误:
This request has been blocked because sensitive information could be
disclosed to third party web sites when this is used in a GET request. To allow
GET requests, set JsonRequestBehavior to AllowGet.
家庭控制器:
public ActionResult NewsLike(int ID)
{
int Like=RNews.Like(ID);
return Json(Like);
}
Rep_New:
public int Like(int ID)
{
var qLike = (from a in db.Tbl_News
where a.ID.Equals(ID)
select a).SingleOrDefault();
try
{
qLike.Like++;
db.Tbl_News.Attach(qLike);
db.Entry(qLike).State = System.Data.Entity.EntityState.Modified;
if (db.SaveChanges() > 0)
{
return qLike.Like;
}
else
{
return qLike.Like--;
}
}
catch (Exception)
{
return qLike.Like;
}
}
News.cshtml:
<table style="margin-top:10px;">
<tr style="color:green;font-size:12px;margin-top:10px;">
<td>Like :</td>
<td><span id="Like@(Counter)">@item.Dislike</span></td>
<td>@Ajax.ActionLink("+", "CommentLike", new { ID = item.ID }, new AjaxOptions { HttpMethod="POST",UpdateTargetId="Like"+Counter})</td>
</tr>
<tr style="color:red;font-size:12px;margin-top:10px;">
<td>DisLike :</td>
<td><span id="DisLike@(Counter)">@item.Dislike</span></td>
<td>@Ajax.ActionLink("+", "CommentDisLike", new { ID = item.ID }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "DisLike" + Counter })</td>
</tr>
</table>
【问题讨论】:
标签: asp.net json ajax asp.net-mvc json.net