Submit form no longer works after adding list of checkboxes (.net mvc razor)

I added a list of checkboxes to the existing form, and now I can no longer submit it. Is this because a field with a required value for data has been added to the checkbox? If so, how can I fix this?

This is the code:

Flag output:

<input name="[0].Id" type="hidden" value="en" />
<input name="[0].Name" type="hidden" value="English" />
<div>
    <input data-val="true" data-val-required="The IsChecked field is required." name="[0].IsChecked" type="checkbox" value="true" />
    <input name="[0].IsChecked" type="hidden" value="false" />
    <label for="">English</label>
</div>

ViewModel:

public class CheckBoxViewModel
{
    public string Id { get; set; }
    public string Name { get; set; }
    public bool IsChecked { get; set; }
}

Partial view:

@model IEnumerable<CheckBoxViewModel>

@using (Html.BeginForm())
{
    @Html.EditorForModel()
}

Editor Template:

@model CloudJunction.Web.MVC4.CloudJunction.Modules.CheckBoxViewModel

@Html.HiddenFor(x => x.Id)
@Html.HiddenFor(x => x.Name)
<div>
    @Html.CheckBoxFor(x => x.IsChecked)
    @Html.LabelFor(x => x.IsChecked, Model.Name)
</div>

The main view:

@using (Html.BeginForm())
{
    // lots of other form items
    @Html.Partial("CheckboxList", Model.LanguageCheckboxes)
    <input type="submit" value="Submit" />
}

I noticed that it creates an additional form tag, can this be the cause of the problems or is it simply ignored?

+4
source share
1 answer

, . , , , - .

, .

, - ?

, .

+3

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


All Articles