I am new to Umbraco. I have a question in its documentation regarding Surface Controller, please see this link https://docs.umbraco.com/umbraco-cms/reference/routing/surface-controllers/
What those statements (highlighted in yellow) means?
Here are my sample codes
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Cms.Web.Website.Controllers;
using UmbracoTest.Infrastructure;
using UmbracoTest.Model;
namespace UmbracoTest.Controllers
{
public class SectionOptionsController : SurfaceController
{
public SectionOptionsController(IUmbracoContextAccessor umbracoContextAccessor,
IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches
appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider
publishedUrlProvider) : base(umbracoContextAccessor, databaseFactory, services,
appCaches, profilingLogger, publishedUrlProvider)
{
}
[HttpPost]
public async Task<IEnumerable<DummyModel>> GetAllDataFromDBAsync()
{
//returns list of data
}
}
}
When I tried to trigger it in Postman it returns 404. I am expecting a list will be returned. Here is the url I used in Postman, https://localhost:44327/Umbraco/surface/SectionOptions/GetAllDataFromDBAsync.
Also, may I request for a high level suggestion on how to implement the below scenario.
Scenario:
-There is a button in UI, and I am planning to make it dynamic. This button will be used in different content page. -If this is clicked, it will display a table that contains data from our database. -This dynamic button will accept an id/flagging that determines what set of data will be displayed in the UI. -For the id/flagging I am planning that this will be populated by the content editor. Depending on the set data needed in each content page.
Thank you in advance.
SurfaceControllers are made to work with Html Form posts. If you want to retrieve data, you should use UmbracoApiControllers.
These will route to ~/Umbraco/Api/[YourControllerName]
The API controller is what I guess you want with your scenario. If you show this table with javascript. If you are rendering the table serverside on a page, consider using RenderControllers