How to create settings

1. Create folder structure in your plugin.

2. Create class for our settings, and file out of model directory called ExamplePluginSettings.cs, which inherit from ISettings interface.


Settings are automatically loaded into contener, you dont have to register them.

3.Create Controller. Make class public and inherit from BasePluginController. 

4.Create action called Configure(), in method create model which was prepared earlier. Now by dependency injection we will load settings to this model, and pass him to view. You can return view without model.

 5. Now we need to create second action, with the same name, but with parameter which is our ConfigurationModel.

This metod is to save our settings.

We will need to add two interfaces to our class; ISettingService to save settings and ILocalizationService to display success message after operation.

It should look like this

6. In Views folder create file _ViewImports.cshtml and paste this code:

@inherits Grand.Framework.Mvc.Razor.GrandRazorPage<TModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Grand.Framework
@using Microsoft.AspNetCore.Mvc.ViewFeatures
@using Grand.Framework.UI
@using Grand.Framework.Extensions

You need it to use TagHelpers, and razor in your views.

7. Now let's go and prepare view. As you can see there is cshtml extension which mean that this is razor page. 

At top declare which model you will use on this page.

Then declare which layout will you use.

Create form, put controller name without "Controller" ending.

Here you can read about <antiforgery-token>

back to top