Model view controller Telerik MVC网格显示属性值与编辑值
希望这将有一个简单的答案 使用MVC3,我将POCO对象的简单列表作为模型传递给我的视图:Model view controller Telerik MVC网格显示属性值与编辑值,model-view-controller,asp.net-mvc-3,telerik,telerik-grid,telerik-mvc,Model View Controller,Asp.net Mvc 3,Telerik,Telerik Grid,Telerik Mvc,希望这将有一个简单的答案 使用MVC3,我将POCO对象的简单列表作为模型传递给我的视图: public partial class PeopleAddress { public int Id { get; set; } public string Address1 { get; set; } public string Address2 { get; set; } public string City { get; set; } public strin
public partial class PeopleAddress
{
public int Id { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public int PersonId { get; set; }
public virtual Person Person { get; set; }
}
我使用PeopleId作为Person实体的FK属性,使用Person导航属性导航到对象。这是我的视图控制器:
public ViewResult Index()
{
var peopleaddresses = db.PeopleAddresses.Include("Person");
return View(peopleaddresses.ToList());
}
非常琐碎。我将列添加到视图中的网格和正常编辑模式等,但用于PersonId属性
关于列的问题:如何使选择正常模式显示model.Person.Name,但将编辑模式保持在editing model.PersonId上?出于模型绑定的目的,我需要HTTP post来发送PersonId
救命啊 简单的
如果当你点击编辑时你需要的只是Person.Id,那么它就是这么简单。你的专栏是:
columns.Bound(e => e.Person).Title("Person").ClientTemplate("<#= Person ? Person.Name : '' #>");
满的
但是,如果您试图使用组合框在网格中进行编辑,您的列应该如下所示:
columns.Bound(e => e.Person).Title("Person").ClientTemplate("<#= Person ? Person.Name : '' #>").EditorTemplateName("PersonSelector");
您的客户端脚本:
onEdit(e){
$comboBox = $(e.cell).find('#Person');
if($comboBox.length > 0) {
var comboBox = $ddl.data('tComboBox');
comboBox.fill(function(){
if (e.dataItem['Person'] != null){
ddl.value(e.dataItem['Person'].Id)
}
});
}
}
@(Html.Telerik().ComboBox()
.Name("YourNameGoesHere")
.DataBinding(binding => binding.Ajax().Select("SelectPeopleForComboBox","Shared")))
onEdit(e){
$comboBox = $(e.cell).find('#Person');
if($comboBox.length > 0) {
var comboBox = $ddl.data('tComboBox');
comboBox.fill(function(){
if (e.dataItem['Person'] != null){
ddl.value(e.dataItem['Person'].Id)
}
});
}
}