I have the following:
Model
public class MyPartialModel
{
// Note, this is NOT nullable
public bool MyBoolean { get; set; }
}
Partial
@model MyPartialModel
@using Html.BeginForm(...) {
@Html.CheckBoxFor(m => m.MyBoolean)
}
Partial Invocation From View
@Html.Partial("MyPartial", new MyPartialModel());
My expected result based on the same syntax in a regular view is:
// Main checkbox
<input id="MyBoolean" name="MyBoolean" type="checkbox" value="false">
// Hidden input rendered by Razor
<input name="MyBoolean" type="hidden" value="false">
My actual result is:
// Main checkbox - note the absence of ="false" on the value
<input id="MyBoolean" name="MyBoolean" type="checkbox" value>
// Hidden input rendered by Razor - note, again, the absence of ="false" on the value
<input name="MyBoolean" type="hidden" value>
The same appears (no value assignment) when I force the value in my model to true as shown here:
public class MyPartialModel
{
// Note, this is NOT nullable and initialized to true
public bool MyBoolean { get; set; } = true;
}
Is this a bug or am I missing something?
Aucun commentaire:
Enregistrer un commentaire