ejs-button target different razor page handler

How do I use the ejs-button control and have the action target a different Razor page handler? I want to use the ejs-button but replicate the functionality provided by:

<button asp-page-handler="Handler2">Post to Handler2</button>

CS code:

public async Task<IActionResult> OnPostHandler2Async()
{
return Page();
}


3 Replies

YA YuvanShankar Arunagiri Syncfusion Team September 23, 2022 09:06 AM UTC

Hi Joe,


We have validated your reported query and prepared the sample based on your requirement. please refer the below code snippet and sample. we can achieve your requirement by using form tag within ejs-button control, we can get click event to cs file.

[razor file]:

<form asp-page-handler="Handler2" method="post">

    <ejs-button id="element" cssClass="e-primary" content="Post to Handler2"></ejs-button>

</form>


[cs file]:

public void OnPostHandler2()

        {

            var Message = "Hello";

        }


Could you please check the above code and get back to us, if you need any further assistance on this.  


Regards, 

YuvanShankar A


Attachment: button_54311e41.zip


JB Joe Burke September 23, 2022 12:39 PM UTC

Not quite what I was looking for but I seemed to have resolved my issue by adding the 'formaction' attribute to the EJS Button control like the following:

<form method="post">        
        <div class="col-md-2">
            <ejs-button id="btnEjsOne" content="EJS Button to Handler1" formaction="@Url.Page("Test","Handler1")"></ejs-button>
        </div>
        <div class="col-md-2">
            <ejs-button id="btnEjsTwo" content="EJS Button to Handler2" formaction="@Url.Page("Test","Handler2")"></ejs-button>
        </div>
    </form>



YA YuvanShankar Arunagiri Syncfusion Team September 26, 2022 06:52 AM UTC

Thanks for the update, Joe. We are glad that you found a solution and thanks for sharing it with us.


Loader.
Up arrow icon