Page 1 of 1

.Net 3.0 customaction

Posted: Sun Sep 20, 2020 3:33 pm
by wedmondson
How do you make use of custom actions in .Net 3.0?

The only code snippet I can find is this:

Code: Select all

        [HttpPost("customaction")]
        public string CustomAction([FromBody]object jsonString)
        {
            return DocuViewareControllerActionsHandler.customaction(jsonString);
        }
It is not clear to me what "DocuViewareControllerActionsHandler.customaction(jsonString)" does. Is there a way to wire up custom code to DocuViewareControllerActionsHandler? Or do I need to parse the json into an object and build my own custom logic off of it. I have looked at some of the other examples such as "MVC Razor" and "Web Forms" but they don't seem to map onto this example very well.

Documentation for custom action does not really explain how you are supposed to use this method.

Re: .Net 3.0 customaction

Posted: Mon Sep 21, 2020 2:26 pm
by wedmondson
Answering my own question:

The answer still comes from the other examples. I just wasn't mentally connecting the .Net Core documentation with the Razor documentation.

Step One: create a static handler

Code: Select all

public static class Globals
You could name this class anything. It does not have to be "Globals"

Step Two: add a handler method

Code: Select all

 public static void CustomActionDispatcher(object sender, CustomActionEventArgs e)
        {
            switch (e.actionName)
Step Three: subscribe to the custom action event

Code: Select all

        public Startup(IConfiguration configuration, IWebHostEnvironment env)
        {
            ...
            DocuViewareEventsHandler.CustomAction += ImageProcessingGlobals.CustomActionDispatcher;
        }