Kendo DropDownListFor 未向控制器发送结束信息
Kendo DropDownListFor not s ending info to controller
这令人费解。在我的一个 MVC 模型 Project
中,我有两个属性都保存其他模型的 ID,就像这样。
public class Project
{
...
public int PlatformID { get; set; }
public int DepartmentID { get; set; }
...
}
我使用自定义编辑器,在其中使用 kendo 下拉菜单编辑这些字段,使用它们各自的名称和 ID 作为文本和值字段。
<div class="col-md-11 details-item">
@Html.LabelFor(m => m.PlatformID, new { @class = "col-md-4 details-label" })
@(Html.Kendo().DropDownListFor(m => m.PlatformID)
.Name("PlatformID")
.DataValueField("ID")
.DataTextField("PlatformName")
.BindTo((System.Collections.IEnumerable)ViewData["Platforms"])
.HtmlAttributes(new { @class = "col-md-7 details-editor" })
)
</div>
<div class="col-md-11 details-item">
@Html.LabelFor(m => m.DepartmentID, new { @class = "col-md-4 details-label" })
@(Html.Kendo().DropDownListFor(m => m.DepartmentID)
.Name("DepartmentID")
.DataValueField("ID")
.DataTextField("Name")
.BindTo((System.Collections.IEnumerable)ViewData["Departments"])
.HtmlAttributes(new { @class = "col-md-7 details-editor" })
)
</div>
疯狂的是 PlatformID
完美保存,但 DepartmentID
甚至没有发送到控制器。如果 DepartmentID
是我在编辑时唯一更改的内容,它甚至不会记录所做的更改。否则,它将作为默认值 0 发送。
Department
class 非常简单。
public class Department
{
[Key]
public int ID { get; set; }
[DisplayName("Department Name")]
public string Name { get; set; }
}
PlatformID
本质上是相同的。也许我遗漏了一些愚蠢的东西,或者也许有邪恶在进行。感谢您提供的任何帮助!
找出答案 - 如果项目可为空,那么在编辑器模板中使用 DropDown 是行不通的!所以我只是在我的项目模型中将 public int? DepartmentID
更改为 public int DepartmentID
,生活再次美好起来。
这令人费解。在我的一个 MVC 模型 Project
中,我有两个属性都保存其他模型的 ID,就像这样。
public class Project
{
...
public int PlatformID { get; set; }
public int DepartmentID { get; set; }
...
}
我使用自定义编辑器,在其中使用 kendo 下拉菜单编辑这些字段,使用它们各自的名称和 ID 作为文本和值字段。
<div class="col-md-11 details-item">
@Html.LabelFor(m => m.PlatformID, new { @class = "col-md-4 details-label" })
@(Html.Kendo().DropDownListFor(m => m.PlatformID)
.Name("PlatformID")
.DataValueField("ID")
.DataTextField("PlatformName")
.BindTo((System.Collections.IEnumerable)ViewData["Platforms"])
.HtmlAttributes(new { @class = "col-md-7 details-editor" })
)
</div>
<div class="col-md-11 details-item">
@Html.LabelFor(m => m.DepartmentID, new { @class = "col-md-4 details-label" })
@(Html.Kendo().DropDownListFor(m => m.DepartmentID)
.Name("DepartmentID")
.DataValueField("ID")
.DataTextField("Name")
.BindTo((System.Collections.IEnumerable)ViewData["Departments"])
.HtmlAttributes(new { @class = "col-md-7 details-editor" })
)
</div>
疯狂的是 PlatformID
完美保存,但 DepartmentID
甚至没有发送到控制器。如果 DepartmentID
是我在编辑时唯一更改的内容,它甚至不会记录所做的更改。否则,它将作为默认值 0 发送。
Department
class 非常简单。
public class Department
{
[Key]
public int ID { get; set; }
[DisplayName("Department Name")]
public string Name { get; set; }
}
PlatformID
本质上是相同的。也许我遗漏了一些愚蠢的东西,或者也许有邪恶在进行。感谢您提供的任何帮助!
找出答案 - 如果项目可为空,那么在编辑器模板中使用 DropDown 是行不通的!所以我只是在我的项目模型中将 public int? DepartmentID
更改为 public int DepartmentID
,生活再次美好起来。