Binder model null in the <object> list sometimes

I have a view model, and one of the properties of the view model is an object called Profile. One of the properties of a profile is a list of another object called a CD. In the view, I set the POST body values ​​as follows

Profile.CD[0].Prop1=TEST&Profile.CD[0].Prop2=TEST&Profile.CD[1].Prop1=TEST2&Profile.CD[1].Prop2=TEST2

If I have to add a third object to the list in the view to be published as Profile.CD[2].Prop1=TEST3, in the controller all sudden ones Profile.CDwill be empty. 2 elements and below Profile.CDget the values ​​I would expect. As soon as I add to this third element, the model binder stops working. I am in my mind and I tried everything I could think of.

Things i tried

  • Removing an item from a view and adding a new one - WORKS

  • Removing both from the view and adding 2 new elements - WORKS

  • Adding a third element to the view - FAILS Profile.CDis null in the view model

I do not use any rules for checking the state of the model. When debugging in the nearest window, ?Request.Form.Where(x => x.Keys.Contain("Profile.CD")).ToList())I tried something like the following: all my values ​​are present in the object Request, although in the view model this list is zero.

The values ​​of the objects in Profile.CDdo not have to be unique .. I tried setting each value to "TEST" to make sure that this is not the input causing this problem.

I am really lost.

Show model

public class PortalViewModel {
     public ProfileModel Profile { get; set; }
}

Profile model

public class ProfileModel {
    //bunch of other static properties that are bound just fine.. like strings and decimals... 

    public List<CDModel> CD { get; set; }
}

controller

public async Task<IActionResult> Edit (PortalViewModel Model)
{
    Repo.UpdateProfile(Model.Profile); // in this method it foreachs Profile.CD , but sometimes this is null and other times it get it values....

    return Ok();
}
+4
source share
1

. , .

.net core 1.0.1 .net core 1.0.5, 100% . , . ​​.net. ..

+1

Source: https://habr.com/ru/post/1686836/


All Articles