DevExpress MVC GridView - 在未将所有属性添加到列时更新后缺少值

时间:2023-02-07 22:34:29

I have DevExpress MVC GridView which is bound to Model (List < Employee >), but I don't have all class properties added as table columns. When UpdateRowRouteValues is called, I'll get new Employee instance in controller method parameter, but not all properties are set (those which are not in columns collection). Is there any way how to get this instance with all properties set (all old values set + modified)?

我有DevExpress MVC GridView绑定到Model(List ),但我没有将所有类属性添加为表列。当调用UpdateRowRouteValues时,我将在控制器方法参数中获取新的Employee实例,但并未设置所有属性(那些不在列集合中的属性)。有没有办法如何设置所有属性设置此实例(所有旧值设置+修改)?

Example: class Employee -FirstName, LastName, Age, IsActive

示例:class Employee -FirstName,LastName,Age,IsActive

Columns: -LastName, Age

列:-LastName,Age

Then in controller I want to have FirstName and IsActive old/unchanged values and new LastName and Age values, but in parameter are FirstName null and IsActive false.

然后在控制器中我想要FirstName和IsActive旧/未更改的值和新的LastName和Age值,但在参数中是FirstName null和IsActive false。

In addition I don't want to add all properties as columns and set Visible=false, because you can still see them in Column Chooser.

另外,我不想将所有属性添加为列并设置Visible = false,因为您仍然可以在Column Chooser中看到它们。

I was thinking about creating new extra class with LastName,Age properties only and then merge these two instances, but not sure if it's the best solution for large project where columns could be changed often (maintain two classes for one table and merge function).

我正在考虑使用LastName,Age属性创建新的额外类,然后合并这两个实例,但不确定它是否是大型项目的最佳解决方案,其中可以经常更改列(为一个表和合并函数维护两个类)。

1 个解决方案

#1


0  

You can either restore the initial (hidden) values from a Model by a key

您可以通过键从模型中恢复初始(隐藏)值

or

use the approach from the GridView - How to implement data editing with hidden column example (i.e., save the edited row's hidden values via custom JSProperties and pass them back to a controller on update).

使用GridView中的方法 - 如何使用隐藏列示例实现数据编辑(即,通过自定义JSProperties保存已编辑行的隐藏值,并在更新时将它们传递回控制器)。

#1


0  

You can either restore the initial (hidden) values from a Model by a key

您可以通过键从模型中恢复初始(隐藏)值

or

use the approach from the GridView - How to implement data editing with hidden column example (i.e., save the edited row's hidden values via custom JSProperties and pass them back to a controller on update).

使用GridView中的方法 - 如何使用隐藏列示例实现数据编辑(即,通过自定义JSProperties保存已编辑行的隐藏值,并在更新时将它们传递回控制器)。