下拉列表的KendoUI编辑器模板不适用于添加项目选项

时间:2014-08-23 19:51:49

标签: razor kendo-ui kendo-asp.net-mvc

我有一个包含4列的KendoUI Web界面 1-Environment-name,2-En​​vironment-code 3-服务器详细信息4-Project-details 所有这些都使用编辑器模板下拉列表来显示除环境名称以外的值,这只是一个文本字段。 当我点击编辑并从所有三个下拉列表中选择值时,它会将值完美地发送到控制器并更新数据库。但是,如果我单击添加新项按钮,服务器详细信息下拉列表和项目详细信息下拉列表不会将值发送到控制器。

这是cs-html文件。

 @(Html.Kendo().Grid<EnvironmentPOCO>()
          .Name("Grid")
          .Columns(columns =>
          {
              columns.Bound(d => d.EnvironmentName).Width(200).Title("Environment Name");
              columns.ForeignKey(d => d.EnvironmentTypeID, (List<EnvironmentTypePOCO>)ViewData["EnvironmentType"], "EnvironmentTypeID", "EnvironmentTypeCode").Width(150).Title("Environment Code").EditorTemplateName("_EnvironmentCodeDropDown");
              columns.ForeignKey(d => d.Server_ID, (List<ServerPOCO>)ViewData["Servers"], "Server_ID", "ServerName").Width(300).Title("Server Details").EditorTemplateName("_ServerDropDown");
              columns.ForeignKey(d => d.Project_ID, (List<SynergyProjectPOCO>)ViewData["SynergyProjects"], "Project_ID", "ProjectName").Width(400).Title("Project Details").EditorTemplateName("_ProjectNameDropDown");         
             // columns.ForeignKey(d => d.ServerID, (List<ServerPOCO>)ViewData["ServerDetails"], "ServerID", "ServerIP").Width(200).Title("Server IP")/*.EditorTemplateName("_ServerIPDropDown")*/;
             // columns.ForeignKey(d => d.ProjectID, (List<SynergyProjectPOCO>)ViewData["SynergyProjects"], "ProjectID", "ProjectDescription").Width(200).Title("ProjectDescription")/*.EditorTemplateName("_ProjectDescription")*/;
              columns.Command(d =>
              {
                  d.Edit();
                  d.Destroy();

              }).Width(200).Title("Action");
          }

          )

          .ToolBar(tools => tools.Create())
          .Sortable()
          .Pageable()
          .AutoBind(true)
          .Filterable()
          //.Scrollable()
          .DataSource(dataSource => dataSource
            .Ajax()
                .Model(model =>
                    {
                        model.Field(m => m.EnvironmentTypeID);

                        model.Field(m => m.Server_ID);                  

                        model.Field(m => m.Project_ID);
                        model.Field(m => m.EnvironmentName);
                        model.Id(m => m.EnvironmentID);

                    })
                .Read(read => read.Url(ViewBag.ApiBaseUrl).Type(HttpVerbs.Get))
                .Create(create => create.Url(ViewBag.ApiBaseUrl).Type(HttpVerbs.Post))
                .Update(update => update.Url(ViewBag.ApiBaseUrl).Type(HttpVerbs.Put))
                .Destroy(destroy => destroy.Url(ViewBag.ApiBaseUrl).Type(HttpVerbs.Delete))
          )

    )

_EnvironmentCodeDropDown编辑器模板

@(Html.Kendo().DropDownListFor(m => m)
                  .Name("EnvironmentTypeID")
                  .OptionLabel("Select Envrionment Type")
                  .DataTextField("EnvironmentTypeCode")
                  .DataValueField("EnvironmentTypeID")
                  .BindTo((List<EnvironmentTypePOCO>)ViewData["EnvironmentType"])
            )

_ProjectNameDropDown编辑器模板     @using List.Model.Model

@(Html.Kendo().DropDownListFor(m => m)
                  .Name("Project_ID")
                  .OptionLabel("Select Project Name")
                  .DataTextField("ProjectName")
                  .DataValueField("Project_ID")
                  .BindTo((List<SynergyProjectPOCO>)ViewData["SynergyProjects"])
            )

_ServerDropDown EditorTemplate @using List.Model.Model

@(Html.Kendo().DropDownListFor(m => m)
                  .Name("Server_ID")
                   .OptionLabel("Select Server")

                  .DataTextField("ServerName")
                  .DataValueField("Server_ID")
                  .BindTo((List<ServerPOCO>)ViewData["Servers"])
            )

1 个答案:

答案 0 :(得分:0)

我发现上述代码没有任何问题,您的数据库中一定存在问题。请检查您的数据库外部列必须设置为非null。这可能会解决您的问题。