I'm using ASP.NET Core MVC & JQuery.
Are you trying to use British English date format?
If so, I have an ongoing battle with it when using ASP Net Zero as it seems give it USA date settings.
As an example, if I select the ASP Net Zero Language from the dropdown as French then I get "dd/mm/yyyy" which is correct. But if I set the Language to British English (en-gb) I get the US Date format "mm/dd/yyyy" instead of "dd/mm/yyyy",despite specifying en-gb when setting adding the Language as an option to the list.
Out of desperation I have totally removed the US English "en" option from the database. It then seems to behave itself. Might be worth a try.
Yes of course Aaron, HTML Helpers. It was a late night!
I'm using the ASP Net Zero Tools to generate my ViewModels etc.
I prefer to use strongly typed TagHelpers, so I convert a lot of the generated form inputs to TagHelpers. All works as expected except for the Validation.
For example, the Zero Tools creates a ViewModel called CreateOrEditClientCaseModalViewModel.
public class CreateOrEditClientCaseModalViewModel
{
public CreateOrEditClientCaseDto ClientCase { get; set; }
public string ClientName { get; set;}
public bool IsEditMode => ClientCase.Id.HasValue;
}
To bind to data in my Dto I want to use the following standard approach
@Html.TextBoxFor(m => m.ClientCase.ClientName)
However, if this is a required field the Validation will reject it with the following message "The ClientName is a required field" so it's obviously looking for "ClientName " and not "ClientCase.ClientName" or "ClientCase_ClientName".
It seems that the Validation is taking place against the Dto and not the ViewModel.
So my question is, how do I change it to get the Validation to use the ViewModel and not the Dto?
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.
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);
}
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?
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?
A vote from me too. It's been a real pain to try to get it to integrate.
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?