0

I Creating a News Site With ASP.Net MVC5 . Every News has a Like And DisLike .

i Using Ajax and Json for Ban Refresh The Page .

But When i Clicked in Like Or DisLike Show Me This Error :

 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.

HomeController :

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>

2 Answers 2

3
public JsonResult NewsLike(int ID)
{
    int Like=RNews.Like(ID);
    return Json(Like, JsonRequestBehavior.AllowGet);
}

you have to provide JsonRequestBehavior to return Json result to view.

Note: Json request Get behavior and HTTP Get request are not same.

Sign up to request clarification or add additional context in comments.

1 Comment

When i Used This Update . Open New Tab then Show The Like
1
return Json(result, JsonRequestBehavior.AllowGet);

Update, try this

public ActionResult NewsLike(int ID)
{
   int Like=RNews.Like(ID);
    return Json(Like, JsonRequestBehavior.AllowGet);
}

4 Comments

I Need Just The Post Method Not Get
When i Used This Update . Open New Tab then Show The Like
@Kianoush Any problem? You mark this as answer but does your problem solved?
i Put This Question For Solved The Post Problem Not Get

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.