I've trying to make a POST request. It is returning the same page, i.e the whole HTML instead of the result I send via the Controller.
@model kgSitecoreTraining.Models.BlogVotes
<div class="blog-vote">
<div id="vote-form">
<input type="button" class="up" id="up" name="up" value=@Model.Up>
<input type="button" class="down" id="down" name="down" value=@Model.Down>
</div>
</div>
<script>
window.addEventListener('load',
function () {
$('#up').on('click', function (event) {
$.ajax({
type:"POST",
url: window.location.href,
context: this,
data: "{ scController: 'BlogVotes', scAction: 'test', option: 'op'}",
success: function (data) {
console.log(data);
},
error: function (error) {
alert(error);
console.dir(error);
}
});
event.preventDefault();
});
}, false);
</script>
And this is the controller
using kgSitecoreTraining.Models;
using Newtonsoft.Json;
using Sitecore.Links;
using Sitecore.Mvc.Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Script.Serialization;
namespace kgSitecoreTraining.Controllers
{
public class BlogVotesController : Controller
{
// GET: BlogVotes
public ActionResult Index()
{
return View(CreateModel());
}
[HttpPost]
public JsonResult test(string option)
{
return Json(option);
}
private BlogVotes CreateModel() {
var item = RenderingContext.Current.Rendering.Item;
var model = new BlogVotes()
{
Up = Int32.Parse(item["Up"]),
Down = Int32.Parse(item["Down"]),
UrlPost = LinkManager.GetItemUrl(item).ToString()
};
return model;
}
}
}
As I said, instead of returning the JSON, It's returning the HTML. Any Idea why?