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 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,但在编辑 model.PersonId 时保持编辑模式?出于模型绑定的目的,我需要 HTTP post 来发送 PersonId。
救命!
Hopefully this will have a simple answer.
Using MVC3, I am passing a simple list of POCO objects as a model to my view:
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; }
}
I use the PeopleId as the FK property to the Person entity, and the Person navigational property to navigate to the object. Here is my controller for the view:
public ViewResult Index()
{
var peopleaddresses = db.PeopleAddresses.Include("Person");
return View(peopleaddresses.ToList());
}
Pretty trivial. I add the columns to the grid and normal edit modes, etc in the view, but for the PersonId property.
QUESTION ABOUT COLUMNS: How can I get the select (normal) mode to display the model.Person.Name, but keep the edit mode on editing model.PersonId? For model binding purposes, I need the HTTP post to send PersonId.
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单
如果您在点击编辑时需要的只是 Person.Id(您在网格之外进行编辑或其他内容),那么就这么简单。您的列将是:
您可以获得此人的 ID:
完整
但是,如果您尝试使用组合框在网格中进行编辑,您的列应如下所示:
您的编辑器模板:
您的客户端脚本:
Simple
If all you need is the Person.Id when you hit edit (you're editing outside the grid or something), then it IS that simple. Your column would be:
And you can get the Id for the person:
Full
However, if you're trying to edit in the grid using a combobox, your column should look like:
your editor template:
Your client script: