CheckBoxFor and ListBoxFor do not behave in the same way when making a post with them?

0

I have a form in which I occupy ListBoxFor and CheckBoxFor for them I have their respective classes which are the following.

public class SelectViewModel
{
    public List<SelectListItem> MiPropiedad { get; set; }
    public List<int> SelectedMiPropiedad { get; set; }
}

public class CheckViewModel
{
    public List<SelectListItem> MiPropiedad { get; set; }
    public List<int> SelectedMiPropiedad { get; set; }
}

Finally a new class with a constructor

public class InputViewModel
{
    public InputViewModel()
    {
        this.SelectViewModel = new SelectViewModel();
        this.CheckViewModel = new CheckViewModel();
    }

    public SelectViewModel SelectViewModel { get; set; }
    public CheckViewModel CheckViewModel { get; set; }
}

View CheckBoxFor

@Html.HiddenFor(m => m.CheckViewModel.MiPropiedad[].Value)
@Html.HiddenFor(m => m.CheckViewModel.MiPropiedad[].Text)
    <label>
        @Html.CheckBoxFor(m => m.CheckViewModel.MiPropiedad[].Selected)
        <span class="title">@Model.CheckViewModel.MiPropiedad[].Text</span>
    </label>

View ListBoxFor

@Html.ListBoxFor(m => m.SelectViewModel.SelectedMiPropiedad, Model.SelectViewModel.MiPropiedad)
<label>...</label>

At the moment of arriving at the data in my checkbox, all the checkboxes that exist in my view come with a property selected of type bool but in my select this property does not appear, it simply returns me a array with the values.

How can I make this field appear on my server when I post the form?

    
asked by vcasas 05.06.2018 в 22:41
source

0 answers