Base solution for your next web application
Open Closed

Problems saving Telerik MultiSelect data #5366


User avatar
0
Mitch created

I'm using the Core MVC and jQuery with Telerik Controls.

All controls are working well except for the MultiSelect. It must be bound to a String array to pass the selected values to the control.

public string[] CaseConditionsArray { get; set; }

I can successfully pass the previously selected values to the control and they display correctly. I can also add or remove additional items from the selected list.

My problem occurs when I need to save the data. I get a validation popup message "Your request is not valid!" "The following errors were detected during validation - ". However, nothing is listed.

In the Logs.txt the following errors are logged

WARN  2018-07-12 00:38:58,739 [39   ] Mvc.ExceptionHandling.AbpExceptionFilter - Method arguments are not valid! See ValidationErrors for details.
Abp.Runtime.Validation.AbpValidationException: Method arguments are not valid! See ValidationErrors for details.
   at Abp.Runtime.Validation.Interception.MethodInvocationValidator.ThrowValidationError()
   at Abp.Runtime.Validation.Interception.MethodInvocationValidator.Validate()
   at Abp.AspNetCore.Mvc.Validation.AbpValidationActionFilter.<OnActionExecutionAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()
WARN  2018-07-12 00:38:58,740 [39   ] Mvc.ExceptionHandling.AbpExceptionFilter - There are 1 validation errors:
WARN  2018-07-12 00:38:58,740 [39   ] Mvc.ExceptionHandling.AbpExceptionFilter -  (caseConditionsArray)
INFO  2018-07-12 00:38:58,748 [39   ] etCore.Mvc.Internal.ObjectResultExecutor - Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext.
INFO  2018-07-12 00:38:58,750 [39   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action DpmsCloud.DpmsClientCases.DpmsClientCasesAppService.CreateOrEdit (DpmsCloud.Application) in 321.2847ms
INFO  2018-07-12 00:38:58,754 [39   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 334.6294ms 400 application/json; charset=utf-8

I don't have any issues with any other controls. I'm wondering if the problem is caused by the Multiselect requiring a string array rather than a simple string, int or datetime like the other controls.

Do you have any suggestions how to fix this issue?


9 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    It should be a problem with model binding. Please take a look at the request parameters of the http request header.

    Please share your controller code and parameter model.

  • User Avatar
    0
    Mitch created

    Thanks for responding.

    Since my initial email I've tried to use the standard MVC DropDownList (Multiple) and I'm getting similar problems so the issue isn't Telerik specific.

    Here's the code for the standard MVC dropdown I'm using

    @Html.DropDownList("caseConditions", (MultiSelectList)ViewBag.Categories, new { multiple = "multiple" })
    

    If CaseConditions is a String it just saves only 1 item.

    If CaseConditions is a String[] I get an error. The same shown as before.

    Before sending more code, has anybody had any success using any standard MVC Multi select with ASP Net Zero?

    If so, how did you manage to Post the selected items without errors or only having 1 item saved?

  • User Avatar
    0
    maliming created
    Support Team

    the model binding fails when you save the data, please share the http request header information of your submitted data and the parameter model corresponding to the method of saving the data.

  • User Avatar
    0
    Mitch created

    As requested, the following was what I was getting for the Telerik control when bound to a String[].

    Response {"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"Your request is not valid!","details":"The following errors were detected during validation.\r\n - \r\n","validationErrors":[{"message":"","members":["caseConditionsArray"]}]},"unAuthorizedRequest":false,"__abp":true}

    Request Payload {"id":"6effe3ec-5e0d-4dee-a4ba-a7e187f15cec","dpmsClientId":"0a3c603f-4e0b-43d5-05ae-08d5e0c249cb","caseStartDate":"03/07/2018","caseEndDate":"","caseFlag":"","caseConditionsArray":"Do not visit home","casePriorityMessage":"","ageAtReferral":"","caseNewReturner":"New","caseRole":"Survivor","timeElapsedBeforeSupport":"","caseLocation":"","currentSituation":"","currentStatus":"","statusFrequency":"","initialSituation":"","initialStatus":"","initialFrequency":""}

    [AbpMvcAuthorize(AppPermissions.Pages_DpmsClientCases_Create, AppPermissions.Pages_DpmsClientCases_Edit)]
            public async Task<PartialViewResult> CreateOrEditModal(Guid? id)
            {
    			GetDpmsClientCaseForEditOutput getDpmsClientCaseForEditOutput;
    
    			if (id.HasValue){
    				getDpmsClientCaseForEditOutput = await _dpmsClientCasesAppService.GetDpmsClientCaseForEdit(new EntityDto<Guid> { Id = (Guid) id });
    			}
    			else{
    				getDpmsClientCaseForEditOutput = new GetDpmsClientCaseForEditOutput{
    					DpmsClientCase = new CreateOrEditDpmsClientCaseDto()
    				};
    			}
    
                var viewModel = new CreateOrEditDpmsClientCaseModalViewModel()
                {
    				DpmsClientCase = getDpmsClientCaseForEditOutput.DpmsClientCase,
    					DpmsClientName = getDpmsClientCaseForEditOutput.DpmsClientName
                };
    
                viewModel.DpmsClientCase.CaseConditionsArray = viewModel.DpmsClientCase.CaseConditions.Split(',');
    
                return PartialView("_CreateOrEditModal", viewModel);
            }
    
  • User Avatar
    0
    maliming created
    Support Team

    What is the model of the CreateOrEdit method? If you can use the ABP template project (<a class="postlink" href="https://aspnetboilerplate.com/Templates">https://aspnetboilerplate.com/Templates</a>) to reproduce this error, please send me a look at the project.

    email:[email protected]

  • User Avatar
    0
    Mitch created

    Many thanks for your offer of help. I've spent about 4 hours stripping my app down to the bare bones so that I can send you a representative example of the problem.

    The email has just been sent to you along with a WeTransfer file as the app is too big to attach to an email.

  • User Avatar
    0
    maliming created
    Support Team

    I have received it and I will check it.

  • User Avatar
    0
    richardghubert created

    Hi. Could you tell us precisely which product from Telerik you are using: is this the (best) one: <a class="postlink" href="https://www.telerik.com/aspnet-core-ui">https://www.telerik.com/aspnet-core-ui</a> Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    @richardghubert if you are using ASP.NET Core & jQuery version, then this is the best option I guess.