Base solution for your next web application
Open Closed

Web Api services called with Wrong Serialized Value #7860


User avatar
0
andyfuw created

After created an entity by using Power Tools, it generated all those stuff, but we've had a strange issue, which is one of the enum field in advanced filter value shall not be passed and serialized correctly when calling backend xxxAppServices.getAll web api, however other enum field doesn't have such issue.

The detailed information is showing as belowing two screenshot:

this is front end, when I check the opion value which is binding correctly, the value of "All" is -1

by debugging, the value of "MDRecStatusFilter" serialized into the "GetAllCustomersInput" class inance is actually 0, which is not correct (shall be -1 as above), I changed the option selected in page several times, actully this property always will  get value 0 populated, which seems the serialization process may not be able to serialize this property, and leave it as default value.

Even I suspect it maybe serialize issue, I don't know where I should look at to fix this right now, Could anyone share some light on this issue?

Thanks


5 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, can you share the ANZ version and framework?

    Also, you can try taking a look at the network request to understand model/input binding better.

  • User Avatar
    0
    andyfuw created

    ANZ V7.2 ASP.NET Core MVC + JQuery

  • User Avatar
    0
    maliming created
    Support Team

    @andyfuw Please share the code for the GetAllCustomersInput class. If its properties are enum types, please also share the code for these enum types.

  • User Avatar
    0
    andyfuw created

    @maliming I've fixed this issue by renaming the property name in index.js file.

    I believe this issue may be relevant to the name I used for this column, which is MDRecStatus. its camelCase name (Auto converted I believe) used in Dynamic Javascript proxies(mDRecStatusFilter)  is different with the camelCase name used in Index.js file (mdRecStatusFilter), I think that's why when calling the web api, the property is not populated since the inputFilter property name is not maching the proxies generated.

    For fxing this, I've modified the property name from mdRecStatusFilter to mDRecStatusFilter in Index.js file**,** so that it matches the proxies' definition, but still I wonder how could I fix this more elegantly, Can I change or interfer the generated Dynamics JS proxies code? and how to avoid this in future? seems the camelCase convert logic is not consistent between generated Dynamics JS proxies and page js file.

    the bellowing is detailed inforamtion:

    After investigating the network request, I found the parameter MDRecStatusFilter is not passing to the web Api. the query string parameters showing as below:

    The camelCase name is different between Proxies and index.js file:

    1.genreated Dynamics JS proxies for the customer.getall, it use mDRecStatusFilter: 2. index.js file, it actully used mdRecStatusFilter:

    <br> Code sharing:

    Enum type:

      public enum MasterDataRecStatus
        {
            New =1,
            DataGovernance =2,
            ChangePendingOnPub =3,
            InactivePendingOnPub =4,
            Published =5,
            PublishedOnInactive = 6
        }
    

    GetAllCustomerInput class:

    public class GetAllCustomersInput : PagedAndSortedResultRequestDto
    {
    public string Filter { get; set; }
    
    public string NameFilter { get; set; }
    
    public int CustCategoryFilter { get; set; }
    
    public int CustClassificationFilter { get; set; }
    
    public string CustPhoneFilter { get; set; }
    
    public string CustMobileFilter { get; set; }
    
    public string StreetFilter { get; set; }
    
    public string AddressDetailFilter { get; set; }
    
    public int RecStateFilter { get; set; }
    
    public int MDRecStatusFilter { get; set; }
    
    public string PostalCodeFilter { get; set; }
    
    
    public string AddrCountryNameFilter { get; set; }
    
    public string AddrProvinceNameFilter { get; set; }
    
    public string AddrCityNameFilter { get; set; }
    
    public string AddrDistrictNameFilter { get; set; }
    
    public string MasterDataVersionNameFilter { get; set;}
    
    public string ContactNameFilter { get; set; }
    }
    
  • User Avatar
    0
    maliming created
    Support Team

    I will give feedback to Power Tools.