I am running into another validation issue on one of my forms. I cannot figure out how to fix this issue. I'm not saying this is an issue of the aspnetzero template. But this was code that was working just fine prior to my V4.x upgrade. I have an entity named "Prospect" in my application. The create modal for this entity only has about 4/5 required fields, everything else is optional and no values are required by the user. However the ABP validation mechanism is firing an error message on my all my optional fields (all dropdowns). All my dropdowns have a value of "null" on the seed entry.
var defaultItem = new ComboboxItemDto("null", L("NotAssigned"));
I copied this from the edition app service below.
public async Task<List<ComboboxItemDto>> GetEditionComboboxItems(int? selectedEditionId = null)
{
var editions = await _editionManager.Editions.ToListAsync();
var editionItems = new ListResultDto<ComboboxItemDto>(editions.Select(e => new ComboboxItemDto(e.Id.ToString(), e.DisplayName)).ToList()).Items.ToList();
var defaultItem = new ComboboxItemDto("null", L("NotAssigned"));
editionItems.Insert(0, defaultItem);
if (selectedEditionId.HasValue)
{
var selectedEdition = editionItems.FirstOrDefault(e => e.Value == selectedEditionId.Value.ToString());
if (selectedEdition != null)
{
selectedEdition.IsSelected = true;
}
}
else
{
defaultItem.IsSelected = true;
}
return editionItems;
}
Here are the errors logged in the log file: [https://drive.google.com/file/d/0B5HAoiVVXzY7T0pzVVh3NWY5VU0/view?usp=sharing]). All of the fields mentioned in the log file are optional and should not be flagged by the ABP validation method as errors.
Can someone help me on how I can suppress this validation error?
9 Answer(s)
-
0
I just deployed my application to my hosting site and I was doing the setup for my domain from the "maintenance" page in the host application. Even on that page, I ran into the exact same error with a dropdown, see image below, on the edition dropdown. [https://drive.google.com/file/d/0B5HAoiVVXzY7S2VzMzMtVWZWdDg/view?usp=sharing]) If I choose an edition and then click SAVE, the error does not happen. So essentially you are forced to select something in the dropdown. This is an exact replication of the problem I am facing on my "prospect" entity form dropdowns.
-
0
As a test have you tried to DisableValidation on the controller method? <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Validating-Data-Transfer-Objects">https://aspnetboilerplate.com/Pages/Doc ... er-Objects</a>
Also on the views do you have an AntiForgeryToken? Something like: @Html.AntiForgeryToken()
I had similar issues with my jQuery forms but not specific to the 4.4 upgrade rather from aspnetboilerplate.
-
0
Hi @exlnt,
Can you appl changes in this file to your version (Areas/Mpa/Views/HostSettings/Index.js) <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/commit/1ffb32a129854c45ebed12958563f8ed3d528849#diff-0ee402dc6b494081c40364034de66cf7">https://github.com/aspnetzero/aspnet-ze ... 034de66cf7</a>
Thanks.
-
0
<cite>ismcagdas: </cite> Hi @exlnt,
Can you appl changes in this file to your version (Areas/Mpa/Views/HostSettings/Index.js) <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/commit/1ffb32a129854c45ebed12958563f8ed3d528849#diff-0ee402dc6b494081c40364034de66cf7">https://github.com/aspnetzero/aspnet-ze ... 034de66cf7</a>
Thanks.
I can live with the issue on the maintenance page as I dont need to use it that often. I only showed that to you as example of the issue I am facing on my custom entity page. How does this fix apply to my custom entity form?
-
0
<cite>ervingayle: </cite> As a test have you tried to DisableValidation on the controller method? <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Validating-Data-Transfer-Objects">https://aspnetboilerplate.com/Pages/Doc ... er-Objects</a>
Also on the views do you have an AntiForgeryToken? Something like: @Html.AntiForgeryToken()
I had similar issues with my jQuery forms but not specific to the 4.4 upgrade rather from aspnetboilerplate.
Thanks for your tips and suggestions. I tried the disable validation on the app service method that is getting called and it did not make a difference! As for the AntiForgeryToken I have never used that on any of my pages and as per what I read in the ABP docs, it is automatically included in all pages by the ABP framework. So not sure if that would make any difference. Thanks again!
-
0
I tried by applying the following code into my createModal.js file for Prospect.
if (prospect.AddressType === "null") { prospect.AddressType = null; } if (prospect.Salutation === "null") { prospect.Salutation = null; } if (prospect.Gender === "null") { prospect.Gender = null; }
I added one of these IF conditions for each of the dropdowns where I am getting the validation. It works for all but one of the one shown below?
if (prospect.CountryId === "null") { prospect.CountryId = null; }
App service POST values sent: [https://drive.google.com/file/d/0B5HAoiVVXzY7X2NvYWUzd3ZWcFE/view?usp=sharing])
Validation Error on country Id: [https://drive.google.com/file/d/0B5HAoiVVXzY7My1qN2dORUs4ems/view?usp=sharing])
It still keeps reporting the same error message on this one dropdown now. Even though a value of "null" is being set. This is completely baffling! :?
-
0
Hi,
Can you lastly share your DTO which contains CountryId field ?
Thanks.
-
0
<cite>ismcagdas: </cite> Hi,
Can you lastly share your DTO which contains CountryId field ?
Thanks.
Your question just helped me find the root cause of the countryId error. This WAS in my DTO:
public int CountryId { get; set; }
I changed it to this NOW:
public int? CountryId { get; set; }
This resolved the error!
I have a couple of questions for support team on this issue.
- Do I need to apply these type of IF conditions into every view I have where I have optional dropdowns?
- If yes, this does not seem to be a sustainable solution. Is there not something that can be done within the underlying ABP validation module to account for such instances?
- Is there anyway to debug the ABP validation/code that takes place, as that would be very helpful to find such issues as the one I reported on this thread?
-
0
Hi exInt ,
This problem is not related with Aspnet Zero framework. It's basics of Asp.net. Could you pls post these kind of questions to <a class="postlink" href="https://forums.asp.net/">https://forums.asp.net/</a>