C# 剑道网格添加新记录不工作
我正在使用编辑器模板编辑记录。但是我在绑定字段中添加外键列,添加新按钮停止工作,但正确编辑工作。这是我的密码C# 剑道网格添加新记录不工作,c#,asp.net-mvc,telerik,kendo-grid,C#,Asp.net Mvc,Telerik,Kendo Grid,我正在使用编辑器模板编辑记录。但是我在绑定字段中添加外键列,添加新按钮停止工作,但正确编辑工作。这是我的密码 @(Html.Kendo().Grid<TelerikMvcTestApp.Models.VM.ReferralViewModel>() .Name("grid") .Columns(c => { c.Bound(i => i.ReferralDate).Title("Date"); c.ForeignKe
@(Html.Kendo().Grid<TelerikMvcTestApp.Models.VM.ReferralViewModel>()
.Name("grid")
.Columns(c =>
{
c.Bound(i => i.ReferralDate).Title("Date");
c.ForeignKey("AssignedMD.ID", (SelectList)ViewData["UserList"]).Title("Assigned MD").Width(200); // When I comment this line, then It works fine
c.Command(cmd =>
{
cmd.Edit();
cmd.Destroy();
});
})
.HtmlAttributes(new { style = "height: 500px;" })
.Scrollable()
.Groupable()
.Sortable()
.ToolBar(tb => tb.Create())
.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("ReferralEdit"))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource =>
dataSource
.Ajax()
.ServerOperation(true)
.PageSize(10)
.Model(model =>
{
model.Id(i => i.ID);
model.Field(i => i.ID).Editable(false);
model.Field(i => i.AssignedMD.ID).DefaultValue(1);
})
.Create(i => i.Action("ReferralCreate", "Referral"))
.Read(i => i.Action("ReferralRead", "Referral"))
.Update(i => i.Action("ReferralUpdate", "Referral").Type(HttpVerbs.Post))
.Destroy(i => i.Action("ReferralDelete", "Referral"))
@(Html.Kendo().Grid())
.名称(“网格”)
.列(c=>
{
c、 绑定(i=>i.ReferralDate)。标题(“日期”);
c、 ForeignKey(“AssignedMD.ID”,(SelectList)ViewData[“UserList”]).Title(“Assigned MD”).Width(200);//当我注释这一行时,它工作正常
c、 命令(cmd=>
{
cmd.Edit();
cmd.Destroy();
});
})
.HtmlAttributes(新的{style=“height:500px;”})
.Scrollable()
.Groupable()
.Sortable()
.ToolBar(tb=>tb.Create())
.Editable(ed=>ed.Mode(GridEditMode.PopUp).TemplateName(“ReferralEdit”))
.Pageable(Pageable=>Pageable
.刷新(真)
.页面大小(真)
.按钮计数(5))
.DataSource(DataSource=>
数据源
.Ajax()
.ServerOperation(真)
.页面大小(10)
.Model(Model=>
{
model.Id(i=>i.Id);
model.Field(i=>i.ID).可编辑(false);
model.Field(i=>i.AssignedMD.ID).DefaultValue(1);
})
.Create(i=>i.Action(“引用创建”、“引用”))
.Read(i=>i.Action(“refereralread”、“reference”))
.Update(i=>i.Action(“ReferralUpdate”,“Referral”).Type(HttpVerbs.Post))
.Destroy(i=>i.Action(“引用删除”、“引用”))
当我评论这一行时,它就可以正常工作了
c.ForeignKey(“AssignedMD.ID”,(SelectList)ViewData[“UserList”]).Title(“Assigned MD”).Width(200);
您需要在网格列中绑定一个编辑器。而不是ForeignKey列,因为此列是只读的,并且不会将dropdownlist选择值发回控制器中的create函数
**************网格模型*****************
public Class ReferralViewModel{
public DateTime UserEditorModel {get; set;}
//along with other grid mode
public UserEditorModel User {get; set;}
}
public Class UserEditorModel
{
public int UserId {get; set;}
public string UserName {get; set;}
}
.Columns(c =>
{
c.Bound(i => i.ReferralDate).Title("Date");
c.Bound(i=>i.User).EditorTemplateName("UserListEditor")
.ClientTemplate("#=User.UserName#");
}
c.Command(cmd => {
cmd.Edit();
cmd.Destroy();
});
})
@(Html.Kendo().DropDownList()
.Name("User") // Name of the widget should be the same as the name of the property
.DataValueField("UserId")
.DataTextField("UserName")
.BindTo(ViewBag.UserList)
)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ReferralViewModel Model)
{
//e.g
var userId=Model.User.UserId;
}
********************网格*********************
public Class ReferralViewModel{
public DateTime UserEditorModel {get; set;}
//along with other grid mode
public UserEditorModel User {get; set;}
}
public Class UserEditorModel
{
public int UserId {get; set;}
public string UserName {get; set;}
}
.Columns(c =>
{
c.Bound(i => i.ReferralDate).Title("Date");
c.Bound(i=>i.User).EditorTemplateName("UserListEditor")
.ClientTemplate("#=User.UserName#");
}
c.Command(cmd => {
cmd.Edit();
cmd.Destroy();
});
})
@(Html.Kendo().DropDownList()
.Name("User") // Name of the widget should be the same as the name of the property
.DataValueField("UserId")
.DataTextField("UserName")
.BindTo(ViewBag.UserList)
)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ReferralViewModel Model)
{
//e.g
var userId=Model.User.UserId;
}
************编辑器***************
public Class ReferralViewModel{
public DateTime UserEditorModel {get; set;}
//along with other grid mode
public UserEditorModel User {get; set;}
}
public Class UserEditorModel
{
public int UserId {get; set;}
public string UserName {get; set;}
}
.Columns(c =>
{
c.Bound(i => i.ReferralDate).Title("Date");
c.Bound(i=>i.User).EditorTemplateName("UserListEditor")
.ClientTemplate("#=User.UserName#");
}
c.Command(cmd => {
cmd.Edit();
cmd.Destroy();
});
})
@(Html.Kendo().DropDownList()
.Name("User") // Name of the widget should be the same as the name of the property
.DataValueField("UserId")
.DataTextField("UserName")
.BindTo(ViewBag.UserList)
)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ReferralViewModel Model)
{
//e.g
var userId=Model.User.UserId;
}
**************创建方法**************
public Class ReferralViewModel{
public DateTime UserEditorModel {get; set;}
//along with other grid mode
public UserEditorModel User {get; set;}
}
public Class UserEditorModel
{
public int UserId {get; set;}
public string UserName {get; set;}
}
.Columns(c =>
{
c.Bound(i => i.ReferralDate).Title("Date");
c.Bound(i=>i.User).EditorTemplateName("UserListEditor")
.ClientTemplate("#=User.UserName#");
}
c.Command(cmd => {
cmd.Edit();
cmd.Destroy();
});
})
@(Html.Kendo().DropDownList()
.Name("User") // Name of the widget should be the same as the name of the property
.DataValueField("UserId")
.DataTextField("UserName")
.BindTo(ViewBag.UserList)
)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ReferralViewModel Model)
{
//e.g
var userId=Model.User.UserId;
}
问候
沙赫扎德