Telerik mvc grid,模型字段到数据库字段名称关系

发布于 2024-10-16 10:35:13 字数 316 浏览 4 评论 0原文

我有一个 Telerik mvc 网格。我正在尝试进行排序工作。我正在将网格绑定到模型集合。该模型的字段名称与数据层的字段名称不同。
当我单击排序按钮时,网格将排序列名称作为我要绑定的模型的属性名称传递。我想将其设置为不同的名称,以使其与我的数据访问层匹配。我之前已经通过向模型的属性添加一个指定相关数据库字段名称的属性来完成此操作。 Telerik 的网格中有类似的东西吗?
我已经尝试过 [Column(Name = "Myname")]

但这似乎被忽略了。
我不想以任何方式配置网格来知道这些名称。 UI层不应该知道DB层的字段名称。有什么方法可以在我的模型中进行设置吗?

I have a Telerik mvc grid. I am trying to get sorting to work. I am binding my grid to a model collection. The model has different names for fields than the data layer.
When i click a sort button the grid passes the sort column name as the property name for the model that i am binding. I want to set that to be a different name, as to have it match my data access layer. I have done this previously by adding an attribute to the properties of the model that specify the related database field names.
Is there anything similar in Telerik's grid?
I have tried
[Column(Name = "Myname")]

but that seems to be ignored.
I do not want to configure the grid in any way to know these names. The UI layer should not be aware of the DB layer's field names. Is there any way i can set this up within my model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸢与 2024-10-23 10:35:13

我不确定我是否理解你想要做什么。示例代码可能会有所帮助。话虽这么说,我会尽力回答你的问题。您可以覆盖用于对 Telerik 网格进行排序的控制器上的方法中的名称。我也有同样的情况,排序没有问题。我将网格直接绑定到模型,它根本不访问数据访问逻辑。 Telerik 网格使用 Linq,因此它应该只对您的集合进行排序,而不必重新连接到数据访问逻辑。我提供了一个在 Telerik 网格上进行排序时调用的控制器方法的示例。 Orderbll.GetAll 返回订单的集合。

[GridAction]
    public ActionResult AjaxIndex()
    {
        // Get all of the orders
        return View(new GridModel(orderBll.GetAll()));
    }

I am not sure if I understand what you are trying to do. Example code would probably help. That being said I will try to answer your question. You could override the name in the method on the controller that you are using to sort the Telerik grid. I have this same situation and I don't have a problem with the sorting. I am binding the grid directly to the Model and it doesn't access the data access logic at all. The telerik grid uses Linq so it should just do the sorting on your collection and not have to reconnect to the data access logic. I have included an example of the controller method that I am calling when doing sorting on my Telerik grid. Orderbll.GetAll returns a collection of orders.

[GridAction]
    public ActionResult AjaxIndex()
    {
        // Get all of the orders
        return View(new GridModel(orderBll.GetAll()));
    }
自由如风 2024-10-23 10:35:13

据我了解,您的模型就是您要查询的内容,并且应该保持一致,以便您可以查询数据库。如果您希望网格列的标题中包含不同的文本,可以在绑定列时使用 Title() 方法来实现:

.Columns(columns =>
{
    columns.Bound(a => a.Surname).Title("Family name");
....

As I understand it, your model is what you're querying, and should be consistent so that you can query the database. If you want different text in the headings of your grid columns, you can do that with the Title() method when binding the column:

.Columns(columns =>
{
    columns.Bound(a => a.Surname).Title("Family name");
....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文