【发布时间】:2021-02-26 01:09:40
【问题描述】:
我正在使用 MVC Razor 视图。
在我的表单顶部,我有以下内容:
@using (Html.BeginForm())
我的复选框、单选按钮或下拉菜单似乎都不起作用,它们都返回 null 值
checkbox : model.Domestic 是一个布尔值,这可能是个问题吗?返回空
@Html.CheckBoxFor(model => model.Domestic.Value, new { value = Model.Domestic.Value ? "checked" : "" }) <span class="display-checkbox">Domestic</span>
单选按钮返回 null
@Html.RadioButtonFor(model => model.Subscription_Renewal, false, new { id = "SR_ChkNo", value = "checked", onclick = "checkButtonDt();" }) <span class="largeText_light">N/A</span>
下拉:
后端代码:
// Create the Categories Select List
var categoryList = new List<SelectListItem>();
foreach (Category c in returned.Categories)
{
categoryList.Add(new SelectListItem
{
Value = c.Category_ID.ToString(),
Text = c.Description,
Selected = (c.Category_ID == returned.Category_ID ? true : false)
});
}
returned.CategoryList = categoryList;
然后在视图中:我试图从所选列表中选择一个条目,它返回 0
@Html.DropDownList("category", Model.CategoryList, new { @class = "input-box" })
【问题讨论】:
标签: c# razor asp.net-core-mvc