Form not triggering OnPost

1 Answer 6 Views
Form
Alex
Top achievements
Rank 1
Alex asked on 24 Apr 2024, 03:39 PM

I have a Form widget on a cshtml file:

@(Html.Kendo().Form<EditEraViewModel>()
            .Name("formEditEra")
            .HtmlAttributes(new { @method = "post" })
            .Orientation("horizontal")
            .Layout("grid")
            .ButtonsTemplateId("buttonsTemplate")
            .Grid(g => g.Cols(1).Gutter(20))
            .FormData(Model.EraViewModel)
            .Validatable(v =>
            {
                v.ValidateOnBlur(false);
                v.ValidationSummary(vs => vs.Enable(false));
            })
                    .Items(items =>
                    {
                        ....
                        });
 
                    })
    .Events(ev => ev.Submit("EditEra.OnTestSubmit"))

I'm adding the button as a template, like this:

<script id="buttonsTemplate" type="text/x-kendo-template">
    <div class="myButtonsContainer">
 
    @if (!isImpersonating)
    {
        @(Html.Kendo().Button()
                .Name(@Localizer["general.page.button.submit"].ToString())
                .HtmlAttributes(new { @class = "k-button k-button-md k-rounded-md k-button-solid k-button-solid-primary k-form-submit" })
                .Content(@Localizer["general.page.button.submit"].ToString())
                .Events(ev => ev.Click("EditEra.onFormSubmit"))
                .ToClientTemplate())
    }
    @(Html.Kendo().Button()
            .Name(@Localizer["general.page.button.cancel"].ToString())
            .HtmlAttributes(new { @class = "k-button k-button-md k-rounded-md k-button-solid k-button-solid-primary k-form-cancel" })
            .Content(@Localizer["general.page.button.cancel"].ToString())
            .Events(ev => ev.Click("goToProviderInfo"))
            .ToClientTemplate()
 
        )
    </div>
</script>

When the submit button is clicked, the OnPost method on the cshtml.cs file is not being triggered. It looks like the form is never submitted.

The "EditEra.OnTestSubmit" function that is called on the Submit event is being called. But the for is not being submitted, and the onPost method on the .cs file is never being executed.

What do I need to do to make sure that the form is submitted when the submit button is clicked?

Thanks.

I do

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 29 Apr 2024, 06:18 AM

Hi Alex,

I noticed that there is no active license which is associated with your account. Be advised that this limits the support service and I would advise you to acquire a new license so that you can get a hold of all the latest features, bug fixes, and support services that the license package offers.

Regardless, I want to help you out further on this one, so what I would suggest is try to add the "type=submit" attribute to the Button which will delegate a form post request to the server. For instance:

@(Html.Kendo().Button()
        .Name(@Localizer["general.page.button.submit"].ToString())
        .HtmlAttributes(new { @class = "k-button k-button-md k-rounded-md k-button-solid k-button-solid-primary k-form-submit", type="submit" })
        .Content(@Localizer["general.page.button.submit"].ToString())
        .Events(ev => ev.Click("EditEra.onFormSubmit"))
        .ToClientTemplate()
)

I hope this helps.

Kind Regards,
Alexander
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Alexander
Telerik team
commented on 29 Apr 2024, 06:19 AM

Forgot to mention, but here are the available Support Plans in case you are curious:

Tags
Form
Asked by
Alex
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or