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:
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?
