Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Elbek 3 posts 83 karma points
    Jun 14, 2020 @ 07:01
    Thomas Elbek
    0

    Umbraco API Controller - use from Template

    I want to use an Umbraco API controller - and I have found this example on how to get access to an Umbraco API Controller from Razor.

    var requestContext = HttpContext.Current.Request.RequestContext;
    var urlHelper = new System.Web.Mvc.UrlHelper(requestContext);
    var url = urlHelper.GetUmbracoApiService("GetAllProducts", "ProductsApiController");
    

    https://our.umbraco.com/Documentation/Reference/Routing/WebApi/routing

    But I can't find any information on what to do next, what Type is url? and how do I make use of it to call the GetAllProducts method?

    Thanks in advance for any help to get me in the right direction.

    /Thomas

  • Graham Davis 110 posts 376 karma points
    Jun 15, 2020 @ 05:26
    Graham Davis
    100

    Hi Thomas,

    I think a parameter is missing. Try: var url = urlHelper.GetUmbracoApiService("GetAllProducts", "ProductsApiController",null);

    Graham

  • Thomas Elbek 3 posts 83 karma points
    Jun 16, 2020 @ 07:29
    Thomas Elbek
    0

    Thanks for reply, I ended up using a different approach with javascript, vue.js and axios and got it all to work from clientside only.

    I think it would be nice to make an Umbraco tutorial on using Umbraco API Controllers from a template with either vue.js or angular as mvvm framework.

    To be able to use javascript from Umbraco template, it's nessecary to understand and use ASP.Net MVC sections.

Please Sign in or register to post replies

Write your reply to:

Draft