这里我使用了两个复选框
<label asp-for="SendReport" class="checkbox-inline"><input type="checkbox" asp-for="SendReport" />Send Report</label><br>
<label asp-for="SendInvoice" class="checkbox-inline"><input type="checkbox" asp-for="SendInvoice" />Send Invoice</label><br>
checboc 的数据类型,即 asp-for="SendReport"和 asp-for="SendInvoice"
是 bit
。
现在的问题是,每当我尝试加载页面时,它都会抛出如下错误
Unexpected 'asp-for' expression result type 'System.Nullable`1[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' for <input>. 'asp-for' must be of type 'System.Boolean' or 'System.String' that can be parsed as a 'System.Boolean' if 'type' is 'checkbox'.<br>
任何帮助都将由衷感谢。谢谢
最佳答案
这是因为 asp-for
在输入类型为 checkbox
时总是需要一个 bool 参数,< strong>或可以解析为 bool 值的字符串参数。
这就是说,假设 SendReport
和 SendInvoice
不是 bool 值:
Unexpected 'asp-for' expression result type 'System.Nullable`
您必须将这些参数更改为默认为 false 的 bool 参数,或者更改为默认包含 "false"
或 "true"
的字符串参数.
关于c# - 复选框中的 asp-for 抛出和 asp.net 核心中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53078044/