Reputation: 107
I've added a checkbox list to an existing form, and now I can't submit it anymore. Is this because there's a data-val-required field added for the checkbox? If so, how can I fix it?
This is the code:
Output of a checkbox:
<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>
Main view:
@using (Html.BeginForm())
{
// lots of other form items
@Html.Partial("CheckboxList", Model.LanguageCheckboxes)
<input type="submit" value="Submit" />
}
I did notice that it creates an extra form tag, could that be causing the problems or is it simply ignored?
Upvotes: 4
Views: 573
Reputation: 1347
Probably there is some binding or build error in the partial view. So when it will runned, there will be an exception, and the submit button is'nt rendering.
Please check the output window.
Clean and rebuild the code, and check the partial view, are there any error?
If there is not error, than the nested form will the responsible for the issue.
Upvotes: 3