Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Disable Abp Validation #5219


User avatar
0
Mitch created

I've generated a number of views with the Rad Tool and I'm using it as a quick way to get started.

I'm then replacing the Rad Tool generated Controls with Telerik UI Core controls and it has worked well except for the validation aspect.

I've tried to replace the Abp validation with Telerik/Kendo validation and replaced the generated code with a Telerik/ Kendo equivalent.

this.save = function () {
    var validator = _$dpmsActivityInformationForm.data("kendoValidator");
    if (!validator.validate()) {
                    return;
    }

An example of my Telerik/Kendo controls is shown below and follows a more traditional MVC approach than the Rad Tool generated code.

<div class="form-group">
    <div class="editor-label">
        <label asp-for="DpmsActivity.StartDate"></label>
    </div>
    @(Html.Kendo().DateTimePickerFor(o => o.DpmsActivity.StartDate)
         .HtmlAttributes(new { style = "width:100%", @class = "form-control" })
     )
    @Html.ValidationMessageFor(m => m.DpmsActivity.StartDate)
</div>

As you can see my ViewModel has a hierarchy which is basically Model.DpmsActivity.StartDate etc.

All of my Client side validation seems to work well but when I go to save I get an error message "Your request is not valid!" as shown in the attachment. It says that fields are required even when they have been filled out! I'm not sure if this error message is generated client side or server side.

I'm wondering if this error message can simply be switched off or something can be done to get it to recognize the correct fields. When the fields were generated by the Rad Tool I noticed they were in the format of "startDate" rather than "DpmsActivity.StartDate" and I'm wondering if that is the issue. However, I don't know how to get it to look for "DpmsActivity.StartDate" instead.

I'm really pleased with the way the Telerik/Kendo client side validation is working, so I just want the error message that's shown in the attachment to either work correctly with "DpmsActivity.StartDate" etc or to be disabled.


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    That's how ASP.NET Core (not ABP) model binding works. The errors are correctly thrown from server because they are null.

    You can implement custom model binding: https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-2.0

  • User Avatar
    0
    Mitch created

    Hi Aaron

    Thanks for responding. To be honest I'm a bit confused, I've been using the MVC version of these controls for years without issue.

    I don't understand why when the values are filled in, the client side validation is satisfied and yet the server side thinks the values are null.

    If I use the following code then the Client Validation works but not Server Side

    @(Html.Kendo().DropDownListFor(m => m.DpmsActivity.Status)

    If I use the following code then the Server Validation works but not Client Side

    @(Html.Kendo().DropDownList() .Name("status") .Value(Model.DpmsActivity.Status)

    The server side seems to be looking for "status" but the client side is looking for "DpmsActivity.Status".

    When the Rad Tool created the form in the first place, it named the control "status" which seems strange as the ViewModel suggests it should be "DpmsActivity.Status". When I changed the controls to Telerik versions I bound them to the ViewModel as would normally be expected. I'm really not sure how to fix this.

    Could it be serializeFormToObject(); that's confusing matters?

  • User Avatar
    0
    aaron created
    Support Team

    You can check what is sent in your browser Network tab.