如何在Kendo UI MVC中保存带有父项的子项列表?

时间:2018-10-21 17:19:07

标签: asp.net-mvc kendo-grid

我有一个称为“访问类型”的表,每个访问类型都有一个访问类型技能列表,我需要将此列表与父级一起保存,但是当我在Kendo Grid中单击“更新”按钮时,访问类型技能列表仍然为空。

这是AddEditVisitType.cshtml代码

@model Evo.FieldFlow.Business.ViewModels.VisitTypeViewModel

                                                                                         基本细节                                                                                                                                                                                                           @ Html.LabelFor(model => model.VisitTypeName,“访问类型名称”,htmlAttributes:new {@class =“ control-label col-md-4 col-sm-12 col-xs-12”})                                                                              @(Html.Kendo()。TextBox()                                                                          .Name(“ VisitTypeName”)                                                                          .HtmlAttributes(new {@required =“”,@autocomplete =“ off”,@class =“ form-control”})                                         )                                                                                                                                                                                                      @ Html.LabelFor(model => model.VisitTypeCode,“ Visit Type Code”,htmlAttributes:new {@class =“ control-label col-md-4 col-sm-12 col-xs-12”})                                                                              @(Html.Kendo()。TextBox()                                                                                  .Name(“ VisitTypeCode”)                                                                                  .HtmlAttributes(new {@required =“”,@autocomplete =“ off”,@class =“ form-control”})                                         )                                                                                                                                                                  
        </div>
    </div>



    <div id="accordion-styled">
        <div class="card">
            <div class="card-header bg-primary">
                <h6 class="card-title">
                    <a data-toggle="collapse" class="text-white" href="#accordion-styled-group3">Skill</a>
                </h6>
            </div>
            <div id="accordion-styled-group3" class="collapse show" data-parent="#accordion-styled">
                <div class="card-body">
                    @(Html.Kendo().Grid<Evo.FieldFlow.Business.ViewModels.VisitTypeSkillViewModel>()
                                                                                                    .Name("VisitTypeSkillGrid")
                                                                                                    .Columns(columns =>
                                                                                                    {
                                                                                                        columns.ForeignKey(x => x.SkillID, (System.Collections.IEnumerable)ViewData["Skills"], "SkillID", "SkillName").Title("Skill").EditorTemplateName("SkillDropdownBox").Groupable(true).Width(200);
                                                                                                       // columns.Bound(p => p.IsActive).Title("Active").EditorTemplateName("IsActiveCheckBox").ClientTemplate("<input disabled type='checkbox' \\#=IsActive ? checked='checked' :'' \\# />").Groupable(true).Width(200);
                                                                                                        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(230);

                                                                                                    })
                                                                                                    .Editable(editable => editable.Mode(GridEditMode.InLine))
                                                                                                    .ToolBar(toolbar =>
                                                                                                    {
                                                                                                        toolbar.Create().Text("Add New Visit Type Skill");
                                                                                                    })
                                                                                                    .DataSource(dataSource => dataSource
                                                                                                    .Ajax()
                                                                                                    .PageSize(20)
                                                                                                    .ServerOperation(true)
                                                                                                    .Model
                                                                                                    (model =>
                                                                                                    {
                                                                                                        model.Id(p => p.VisitTypeSkillID);
                                                                                                    }
                                                                                                    )
                                                                                                    .Create("CreateSkill", "VisitType", new { ID = Model.VisitTypeID.ToString() })
                                                                                                    .Read("ReadListSkill", "VisitType", new { ID = Model.VisitTypeID.ToString() })
                                                                                                    .Update("EditSkill", "VisitType", new { ID = Model.VisitTypeID.ToString() })
                                                                                                    .Destroy("DeleteSkill", "VisitType")
                                                                                                    )
                                                                                                    .Pageable()
                                                                                                    .Sortable()
                                                                                                    .Scrollable()
                                                                                                    .Filterable()
                                                                                                    .Groupable()
                    )
                </div> 
            </div>
        </div>



    </div>

</div>
</div>



<style>
    .k-edit-form-container {
        width: 100% !important;
        box-sizing: border-box;
    }

        .k-edit-form-container .w-100 {
            padding: 15px;
            box-sizing: border-box;
        }
</style>

这是动作创建

[HttpPost]
    public ActionResult Create([DataSourceRequest] DataSourceRequest request, VisitTypeViewModel VisitType)
    {
        try
        {
            VisitType.CreatedByWorkerID = new Guid(Convert.ToString(Profile["UserID"]));
            int result = _VisitTypebusiness.InsertVisitType(VisitType);
            if (result != 0)
            {
                return Json(new[] { VisitType }.ToDataSourceResult(request, ModelState));
            }
            else
            {
                var jsonResult = Json(_VisitTypebusiness.GetAllVisitTypes().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
                jsonResult.MaxJsonLength = int.MaxValue;
                return jsonResult;
            }
        }
        catch (Exception ex)
        {
            return this.Json(new DataSourceResult
            {
                Errors = ex.Message
            });
        }
    }

这是对象属性

public class VisitTypeViewModel
{

    public int VisitTypeID { get; set; }
    [Required(ErrorMessage = "The Visit Type Name is Required")]
    public string VisitTypeName { get; set; }
    public string VisitTypeCode { get; set; }
    public Nullable<System.Guid> CreatedByWorkerID { get; set; }
    public System.DateTime DateCreated { get; set; }
    public System.DateTime LastUpdated { get; set; }
   public List<VisitTypeSkillViewModel> VisitTypeSkills { get; set; }

}

调试时,我看到VisitTypeSkills为空

0 个答案:

没有答案