Hot answers tagged

8

If it's an ajax call you just did from javascript to a normal MVC controller, there is no Sitecore.Context.Item there. What you can do is in your original Sitecore rendering write the id of your item to the generated html (e.g. as a data-itemid attribute) and then pass it with your ajax call back to the server. Thanks to that you will know which item you ...


6

It's worth mentioning that the route in the question is called out in a setting. The comment above Mvc.IllegalRoutes explains itself a bit. <!-- MVC: Pipe separated list of route URL's that are not valid for use with Sitecore.Mvc. For instance, the default ASP.NET route ({controller}/{action}/{id}) catches most requests that are ...


4

First off, @PatrickBarron is absolutely correct about your route. However, there is one other issue that I see. Have you tried dropping the word "Controller" off the name of your controller when making the request? By default, the word Controller will be appended for you. In other words, you are currently requesting this URL: "Website/Controllers/...


4

You cannot redirect from an AJAX post. You could return the URL you want to redirect and redirect from Javascript. success: function(response){ window.location.href = response; }


3

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


3

I found the solution @Html.Sitecore().Rendering() will not work for View rendering type. My rendering was of type View rendering which it was throwing above error. And also I tried with @Html.Sitecore().ViewRendering() for view rendering type, it dint work as expected. So I decided to use Controller rendering to make it work.


3

I would recommend creating a custom route for Ajax functionality that doesn't reside in the Sitecore Shell. From my understanding, using the default route of /api/Sitecore only works if you are logged in, which is why it works in preview but not the rest of the time on your site. Now I'm sure there is a way to change this permission, but you wouldn't want ...


2

In Ajax requests the Sitecore.Context.Item object is NULL. So you can't use it to get the current page. To work around this, you will need to tell the MVC action what the current context item is using its ID. So you will need to pass this ID from the HTML into your MVC action. public ActionResult SubmitForm(string firstName, string lastName, string pageId){...


1

The response from Controller should be JsonResult, in which you can define the Url that you want to redirect. new Json { newurl = link }; Then in the success method of ajax, you can do window.location.href = response.newurl for example.


1

In sitecore MVC always use /api/Sitecore/{controller}/{action}. It should work if you are call from ajax. Sample code: jQuery.ajax({ type: "POST", url: "/api/sitecore/{controller}/{action}", data: '{url: "' + _url + '" }', contentType: "application/json; charset=utf-8", dataType: "html", ...


1

It looks like the URL you are sending the request to doesn't match your route configuration. Your URL is /Website/Controllers/FindAnAffiliateController/getAffiliate and your rout is {controller}/{action}/{id} so it's looking for /FindAnAffiliateController/getAffiliate I would update your route to be Website/Controllers/{controller}/{action}/{id}


Only top voted, non community-wiki answers of a minimum length are eligible