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" [email protected]>
            <input type="button" class="down" id="down" name="down" [email protected]>


        function () {
             $('#up').on('click', function (event) {
                url: window.location.href,
                context: this,
                data: "{ scController: 'BlogVotes', scAction: 'test', option: 'op'}",
                success: function (data) {
                error: function (error) {
        }, false);

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());

        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?

1 Answer 1


From my point of view it's not a correct way for call your api. Try to sent your request in another way: instead of window.location.href try to call http://{hostname}/api/sitecore/BlogVotes/test via HTTP POST

  • Agree completely. Example could look like this: $.post('/api/sitecore/DropdownCart/RemoveLine', { lineId: lineId })
    – Mark Cassidy
    Oct 19, 2017 at 13:03
  • Thanks so much, it worked. Still dont know why the old way return the same page. Oct 19, 2017 at 15:14
  • 1
    Great! When you are trying to send request to window.location.href, Sitecore resolves your request as a request for render Sitecore item and runs pipelines for render item. Also you can register new route and call your api based on route settings. Oct 19, 2017 at 15:20
  • Thank you so much for taking the time to explain. I understand now. Awesome! Oct 19, 2017 at 15:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.