Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

When submitting empty value types, ModelState has a NullRef exception #2720

@sornaks

Description

@sornaks

The view looks like this:

<form asp-action="Create" asp-controller="Home">
@Html.EditorForModel()
<input type="submit" value="ok" />
</form>

The Model is this:

public class Person
{
    [Required]
    public string Name { get; set; }
    public decimal Height { get; set; }
    public double Weight { get; set; }
    public float BMI { get; set; }  
    [Range(1, 40)]
    public short Age { get; set; }
    public ushort IsWorking { get; set; }
}

NullRef is thrown for - Height, Weight etc. This is the stack trace in mono:

"  at Microsoft.Framework.Internal.PropertyHelper.CallPropertySetter[Person,Decimal] (System.Action`2 setter, System.Object target, System.Object value) [0x00000] in <filename unknown>:0 \n  
at Microsoft.AspNet.Mvc.ModelBinding.MutableObjectModelBinder.SetProperty (Microsoft.AspNet.Mvc.ModelBinding.ModelBindingContext bindingContext, Microsoft.AspNet.Mvc.ModelBinding.ModelExplorer modelExplorer, Microsoft.AspNet.Mvc.ModelBinding.ModelMetadata propertyMetadata, Microsoft.AspNet.Mvc.ModelBinding.ModelBindingResult dtoResult) [0x00000] in <filename unknown>:0 "

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions