What Url to use for PluginController used in custom section
I have created a custom section called "Aanmeldingen" and added a file 'edit.html' to /umbraco/views/aanmeldingenTree.
Next I want to retrieve some data by calling AanmeldingenController:
public class AanmeldingenController : UmbracoAuthorizedJsonController
{
//dot stuff here
}
I have tried various URL's to call this method, like:
umbraco/backoffice/aanmeldingen/getalleaanmeldingen
backoffice/aanmeldingen/getalleaanmeldingen
umbraco/aanmeldingen/getalleaanmeldingen
and placed the file containing this code in various location (does that even matter?)
Added a specific route to the RouteConfig.s does't help either.
Your example above doesn't contain a PluginController attribute, when this is the case - eg with the following code:
using Newtonsoft.Json.Linq;
using Umbraco.Web.Editors;
public class AanmeldingenController : UmbracoAuthorizedJsonController
{
public object GetAlleAanmeldingen()
{
return new JArray();
}
}
On the order hand, if you actually do add the PluginController attribute - eg. like in the code below:
using Newtonsoft.Json.Linq;
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
[PluginController("Stuff")]
public class AanmeldingenController : UmbracoAuthorizedJsonController
{
public object GetAlleAanmeldingen()
{
return new JArray();
}
}
the URL for your method will then be as below instead:
I added the PluginController-attribute and I am now able to call the method from script with backoffice/AanmeldingenPlugin/Aanmeldingen/GetAlleAanmeldingen.
a good way to not have to fiddle with your urls in angular is to use the build in ServerVariables ServerVariablesParser.Parsing += Parsing; in a startup evemt. With that you can get the urls to your controller by using
var mainDictionary = new Dictionary<string, object>();
mainDictionary.Add("aanmeldingenBaseUrl", urlHelper.GetUmbracoApiServiceBaseUrl<AanmeldingenController>(controller => controller.GetAlleAanmeldingen(null)));
and adding it to the dictionary provided in the method
if (!e.Keys.Contains("myCustomName"))
{
e.Add("myCustomName", mainDictionary);
}
Then you can use it in your angular controller like this
What Url to use for PluginController used in custom section
I have created a custom section called "Aanmeldingen" and added a file 'edit.html' to /umbraco/views/aanmeldingenTree.
Next I want to retrieve some data by calling AanmeldingenController:
I have tried various URL's to call this method, like: umbraco/backoffice/aanmeldingen/getalleaanmeldingen backoffice/aanmeldingen/getalleaanmeldingen umbraco/aanmeldingen/getalleaanmeldingen
and placed the file containing this code in various location (does that even matter?)
Added a specific route to the RouteConfig.s does't help either.
What is supposedly the correct way to do this?
Hi Bunnynut,
Your example above doesn't contain a
PluginController
attribute, when this is the case - eg with the following code:The URL will be:
On the order hand, if you actually do add the
PluginController
attribute - eg. like in the code below:the URL for your method will then be as below instead:
It's not necessary to add any custom routes, as Umbraco will handle the routing for you automatically.
By the way - you can actually get Umbraco to tell you the correct URL of your method.
If you have an MVC view (or just an instance of
UrlHelper
) in general, you can do something like:Then you'll have the correct URL, which takes the
PluginController
attribute, class name and method name into consideration ;)Hi Anders,
I added the
PluginController
-attribute and I am now able to call the method from script withbackoffice/AanmeldingenPlugin/Aanmeldingen/GetAlleAanmeldingen
.Thanks!
Hi,
a good way to not have to fiddle with your urls in angular is to use the build in ServerVariables
ServerVariablesParser.Parsing += Parsing;
in a startup evemt. With that you can get the urls to your controller by usingand adding it to the dictionary provided in the method
Then you can use it in your angular controller like this
is working on a reply...