The data in the controller is prepared correct and the correct data comes to the view. There is such an outstanding model:

public class InfoServiceSystem : Tuple<bool, InfoServiceSystemBase> { public InfoServiceSystem() : base(false, new InfoServiceSystemBase()) { } public InfoServiceSystem(bool isAvailable, InfoServiceSystemBase item) : base(isAvailable, item) { } public bool IsAvailable { get { return this.Item1; } } public InfoServiceSystemBase ItemBase { get { return this.Item2; } } } 

The properties IsAvailable and ItemBase added for convenience (since Item1 and Item2 cannot be changed, but it is more convenient to use meaningful names).

There is a view containing the following code:

 @using (Html.BeginForm()) { @Html.AntiForgeryToken() ... <table id="tblInfoSystems" class="table table-bordered"> <thead> <tr> ... </tr> </thead> <tr> <td class="align-left">Система...</td> <td>@Html.CheckBoxFor(m => m.SystemsContext.ElSystemInfo.IsAvailable)</td> ... 

Everything is displayed correctly, only if you look at the page code, you will see the following:

Page Code

As you can see, input , which is hidden - is generated false . Previously, I had IsAvailable one of the fields of the InfoServiceSystem class and everything worked correctly, but there was a need for separation and after that strange behavior appeared ... what assumptions would there be about such strange behavior and solutions? Can anyone come across a similar problem?

If you remove:

 @Html.AntiForgeryToken() 

and write everywhere:

 @Html.HiddenFor(m => m.SystemsContext.ElSystemInfo.IsAvailable) 

all the same, the behavior is not the one that we would like. I will make a small amendment, initially it should be generated by the default value ( false in our case), but before sending the values ​​from the form, it is filled with the desired value and what is needed comes to the controller ( true in our case). Previously filled, but now no. Why is that?

  • one
    <del> Wait, this hidden in the table refers to the checkbox, because via GET / POST it is impossible to send a false-value checkbox. Hidden to the token should be somewhere outside the table. </ Del> I apologize, the question is not understood correctly. - kmv
  • @kmv, now I will try to endure - Denis Bubnov
  • @kmv, rendered hiddeny outside the table - works the same way - Denis Bubnov

1 answer 1

The point was that Tuple had non-editable properties. And they cannot be redefined. Therefore, the values ​​from false to true did not change after sending the data from the form, and the controller didn’t get the values ​​that were expected.