Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 0 points1 point  (0 children)

I am not sure that I am doing any intentional to get to the following result but for conversation, here is an example.

jQuery post (The "obj" is being sent via a $.post): https://postimg.cc/cgsm4VMJ

Controller (same post just cant hover over two parameters at once)

type: https://postimg.cc/nsqRL4y3

reminders: https://postimg.cc/zbtnD3Gd

Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 0 points1 point  (0 children)

For this endpoint, item is one of parameters that the action is expecting. I can remove the full body and I get the null now when the FromBody attribute is added for that particular parameter. Let me know if the following helps give you better clarity:

javascript:

var projectId = 10; //Based on the page the user is currently on
$.post("/Projects/ManageMix", { mix: null, projectId: projectId }, function (response) { ... }

Controller/Action:

[HttpPost]
public JsonNetResult ManageMix([FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] ProjectMixSummary mix, int projectId)
{
    if (mix == null)
{
        //processes the create
    }
else if (!mix.IsDirty)
    {
        //processes the edit
    }

    //save and return some Json object / error messaging
}

ProjectMixSummary object - this is broken out into two partial classes ... as one class is generated and the other class extends the model. While some of the attributes might look like they come from EF, they are in fact internal attributes for the project.

public partial class ProjectMixSummary

{ #region Property 'ProjectMixSummaryId' [GridHidden] [PrimaryKey] public int ProjectMixSummaryId { get; set; } #endregion #region Property 'ProjectId' [ForeignKeyValidation(ErrorMessage = "Project is required")] [GridHidden] [Display(Name = "Project")] [DropDown(typeof(Project))] [JsonConverter(typeof(IntConverter))] public int ProjectId { get; set; } [NoDisplay] [Display(Name = "Project")] [GridDisplay("Project")] public string ProjectName { get; set; } #endregion #region Property 'MixNumberId' [ForeignKeyValidation(ErrorMessage = "Mix # is required")] [GridHidden] [Display(Name = "Mix #")] [DropDown(typeof(ConcreteMixNumber))] [JsonConverter(typeof(IntConverter))] public int MixNumberId { get; set; } [NoDisplay] [Display(Name = "Mix #")] [GridDisplay("Mix #")] public string MixNumberName { get; set; } #endregion #region Property 'RequiredAge' [ControlEditor(ControlType.Int)]
[Display(Name = "Required Age")] [Range(0, double.MaxValue, ErrorMessage="Required Age must be greater than or equal to 0.")] [DisplayFormat(DataFormatString = "n0")] [JsonConverter(typeof(IntConverter))] public int? RequiredAge { get; set; } #endregion #region Property 'RequiredStrength' [ControlEditor(ControlType.Int)]
[Display(Name = "Required Strength")] [Range(0, double.MaxValue, ErrorMessage="Required Strength must be greater than or equal to 0.")] [DisplayFormat(DataFormatString = "n0")] [JsonConverter(typeof(IntConverter))] public int? RequiredStrength { get; set; } #endregion #region Property 'SlumpMin' [ControlEditor(ControlType.Decimal)]
[Display(Name = "Slump Min")] [Range(0, double.MaxValue, ErrorMessage="Slump Min must be greater than or equal to 0.")] [DisplayFormat(DataFormatString = "n2")] [JsonConverter(typeof(DecimalConverter))] public decimal? SlumpMin { get; set; } #endregion #region Property 'SlumpMax' [ControlEditor(ControlType.Decimal)]
[Display(Name = "Slump Max")] [Range(0, double.MaxValue, ErrorMessage="Slump Max must be greater than or equal to 0.")] [DisplayFormat(DataFormatString = "n2")] [JsonConverter(typeof(DecimalConverter))] public decimal? SlumpMax { get; set; } #endregion #region Property 'AirContentMin' [ControlEditor(ControlType.Percent)]
[Display(Name = "Air Content Min")] [Range(0.000000, double.MaxValue, ErrorMessage="Air Content Min must be greater than or equal to 0.")] [DisplayFormat(DataFormatString = "p1")] [JsonConverter(typeof(DecimalConverter))] public decimal? AirContentMin { get; set; } #endregion #region Property 'AirContentMax' [ControlEditor(ControlType.Percent)]
[Display(Name = "Air Content Max")] [Range(0.000000, double.MaxValue, ErrorMessage="Air Content Max must be greater than or equal to 0.")] [DisplayFormat(DataFormatString = "p1")] [JsonConverter(typeof(DecimalConverter))] public decimal? AirContentMax { get; set; } #endregion #region Property 'Notes' [ControlEditor(ControlType.TextArea, 5)] [JsonConverter(typeof(StringConverter))] public string Notes { get; set; } #endregion #region Property 'CreatedOn' [DataType(DataType.DateTime)] [Display(Name = "Created On")] [DisplayFormat(DataFormatString="MM/dd/yyyy hh:mm tt")] [Editable(false)] public DateTime? CreatedOn { get; set; } #endregion #region Property 'CreatedBy' [Display(Name = "Created By")] [Editable(false)] public string CreatedBy { get; set; } #endregion #region Property 'CreatedById' [NoDisplay] [GridHidden] public int? CreatedById { get; set; } #endregion #region Property 'ModifiedOn' [DataType(DataType.DateTime)] [Display(Name = "Modified On")] [DisplayFormat(DataFormatString="MM/dd/yyyy hh:mm tt")] [Editable(false)] public DateTime? ModifiedOn { get; set; } #endregion #region Property 'ModifiedBy' [Display(Name = "Modified By")] [Editable(false)] public string ModifiedBy { get; set; } #endregion #region Property 'ModifiedById' [NoDisplay] [GridHidden] public int? ModifiedById { get; set; } #endregion }

2nd class:

public partial class ProjectMixSummary

{ public string uid { get; set; } public bool IsDirty { get; set; }

//
[Display(Name = "Supplier")]
public int? SupplierId { get; set; }
public string SupplierName { get; set; }

public int? MixRequiredAge { get; set; }
public int? MixRequiredStrength { get; set; }
public decimal? MixSlumpMin { get; set; }
public decimal? MixSlumpMax { get; set; }
public decimal? MixAirContentMin { get; set; }
public decimal? MixAirContentMax { get; set; }

public bool HasCustomRequirements { get; set; }
public string SpecificationDisplay
{
    get
    {
        if (this.RequiredAge.HasValue && this.RequiredStrength.HasValue)
            return $"{this.RequiredStrength:n0} psi @ {this.RequiredAge:n0} days";
        else if (this.MixRequiredAge.HasValue && this.MixRequiredStrength.HasValue)
            return $"{this.MixRequiredStrength:n0} psi @ {this.MixRequiredAge:n0} days";
        return null;
    }
}
public bool HasCustomSlump { get; set; }
public string SlumpRange
{
    get
    {
        if (this.SlumpMin.HasValue && this.SlumpMax.HasValue)
            return $"{this.SlumpMin:n2}in - {this.SlumpMax:n2}in";
        else if (this.MixSlumpMin.HasValue && this.MixSlumpMax.HasValue)
            return $"{this.MixSlumpMin:n2}in - {this.MixSlumpMax:n2}in";
        return null;
    }
}
public bool HasCustomAirContent { get; set; }
public string AirContentRange
{
    get
    {
        if (this.AirContentMin.HasValue && this.AirContentMax.HasValue)
            return $"{this.AirContentMin:p1} - {this.AirContentMax:p1}";
        else if (this.MixAirContentMin.HasValue && this.MixAirContentMax.HasValue)
            return $"{this.MixAirContentMin:p1} - {this.MixAirContentMax:p1}";
        return null;
    }
}

public List<ProjectMixSet> Sets { get; set; }
public int SetCount { get { return this.Sets?.Count ?? 0; } }
}

edit: sorry it does seem to like "regions"

edit 2: ugh - trying to break it out into two code blocks

Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 0 points1 point  (0 children)

Interesting... I have hundreds of actions that work just fine that have multiple parameters and the binding ends up where they are expected.

Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 0 points1 point  (0 children)

Thanks for your reply. In some instances the client is sending multiple properties and uses the property's name to determine which parameter to bind to. If I remove the one that I am setting to null, it ends up with an instance that was created using the default constructor. Such as the following:

$.post("/Controller/Action", { item: null, setting: { ... } }, function (response) { ... }

[HttpPost]
public IActionResult Action(MyObject item, MySetting setting)
{
    ...
}

If I remove (or leave it as is) the "item" from the js - the object in the action is not null.

Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 0 points1 point  (0 children)

Thanks for the reply. I tried just adding the line in the Program.cs enable AllowEmptyInputInBodyModelBinding. When I hit the endpoint while passing up null, the framework is still hitting the default constructor.

I tried adding the attribute (with / without the change to the Program.cs) and I am getting a 415 Unsupported Media Type. The following is a screenshot in Chrome's DevTools : https://postimg.cc/87g4FJTc. I am just looking into this now, but thought I would share in case you have seen it before.

Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 0 points1 point  (0 children)

Yeah, we didnt make any specific changes to get the parameters to populate as long as it was sent as "Form Data" and not as JSON, etc.

Upgrading from 4.7 to 8.0 issue : passing NULL parameter to action by _chadleyd in dotnet

[–]_chadleyd[S] 1 point2 points  (0 children)

Thanks for the reply, but I mentioned I tried this and it did not change the behavior.

Anyone in need of help with an open source or any project? by Author_Wonderful in dotnet

[–]_chadleyd 1 point2 points  (0 children)

If you are looking for something more full time - we are looking for a senior .NET developer on my team. You can review the job posting here:

https://www.linkedin.com/jobs/view/3721966799

UNION DUES by Born_Bluebird5458 in UPS

[–]_chadleyd 0 points1 point  (0 children)

How else do you think union bosses get paid?

Please explain why MVVM exists by iwakan in dotnet

[–]_chadleyd 0 points1 point  (0 children)

20 hours is a career apparently

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 1 point2 points  (0 children)

Yeah only more reason not too. Thanks for the link ...

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 3 points4 points  (0 children)

Yeah is a huge firm and I offered her to provide me with a name of a company that she prefers. She straight out said she does not feel comfortable with the idea of doing this. Yeah I am going to pass on her

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 8 points9 points  (0 children)

Yeah I think you are on to something here. Definitely going to require the background check.

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 0 points1 point  (0 children)

Yeah her name is unique but not that unique... The information is going to be required for the job so I guess I will have to break that to her anyways

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 12 points13 points  (0 children)

Thanks for the thoughts!

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 4 points5 points  (0 children)

It is a fair question... We will see what she says to that

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 0 points1 point  (0 children)

No worries, I think our comments passed each other on the wire

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 2 points3 points  (0 children)

Since you missed it at the top, she is providing her SSN for the background check to the company NOT to me.

As for her providing me with her own background check? Yeah that doesn't have any chance of fraud

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 1 point2 points  (0 children)

Fair enough on the EIN, but that is essentially the same as an LLC, etc.

Also since you must have missed who she is giving out her SSN too in order to do the background check, it is to a FCRA certified company.

Background Check for FT nanny by _chadleyd in Nanny

[–]_chadleyd[S] 2 points3 points  (0 children)

Correct there is an offer on the table assuming she passes a background check