What I want to happen here is angular goes off, hits a custom controller which talks to the umbraco back office to determine whether or not the promo code exists and is valid. Either way this controller will return a json object which contains info about whether or not the promo code is valid, something like:
All will be held as either individual nodes in the back office, or as nested content sections on one node, either way I need to hit the controller first.
The start of the controller is like the following:
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using xxx.web.Models;
using Skybrud.WebApi.Json;
using Skybrud.WebApi.Json.Meta;
using Umbraco.Core.Logging;
using Umbraco.Web;
using Umbraco.Web.WebApi;
namespace xxx.web.Controllers
{
[JsonOnlyConfiguration]
public class CheckPromoCodeController : UmbracoApiController
{
private UmbracoHelper _helper = new UmbracoHelper(UmbracoContext.Current);
public object CheckPromoCode()
{
var a = "something"; // breakpoint attached here purely to see if angular hits this
No joy, all im getting is a 404. Now I havnt touched routing at all as im not really sure how to use it yet.
Thanks in advance for any help, and if any more info is required just ask.
As discussed on Slack the URL of your AJAX call is wrong. Instead of '/Controllers/CheckPromoCode' it should be '/Umbraco/Api/CheckPromoCode/CheckPromoCode'. Umbraco API controllers are automatically routed as described here: https://our.umbraco.org/documentation/reference/routing/webapi/routing
Angular access to back office properties from front end
Hey guys, need a little assistance using Angular on the front end, and having this angular talk to the umbraco back office.
I have a custom form, on this form an input for a promo code is added with a button to apply the code.
What I want to happen here is angular goes off, hits a custom controller which talks to the umbraco back office to determine whether or not the promo code exists and is valid. Either way this controller will return a json object which contains info about whether or not the promo code is valid, something like:
All will be held as either individual nodes in the back office, or as nested content sections on one node, either way I need to hit the controller first.
I did set this up using angular $http, like:
The start of the controller is like the following:
No joy, all im getting is a 404. Now I havnt touched routing at all as im not really sure how to use it yet.
Thanks in advance for any help, and if any more info is required just ask.
Hi Dave,
As discussed on Slack the URL of your AJAX call is wrong. Instead of '/Controllers/CheckPromoCode' it should be '/Umbraco/Api/CheckPromoCode/CheckPromoCode'. Umbraco API controllers are automatically routed as described here: https://our.umbraco.org/documentation/reference/routing/webapi/routing
Boom. Have that karma!
I am having trouble posting data to this controller however, my code:
and the controller:
When this is added the $http request returns a 404, isnt even getting there...weird right, or am I missing something?
Ok, got it, after a little faffing I had to do the following:
In the angular $http method:
(notice the JSON.Stringify method)... and then in the C# controller
(notice the [fromBody] attribute in the method arguments)
I cannot take total credit though: check out this - http://jasonwatmore.com/post/2014/04/18/post-a-simple-string-value-from-angularjs-to-net-web-api thats where I found my answer.
is working on a reply...