How to: Display a Detail View Directly in Edit Mode in ASP.NET Applications 如何:在ASP.NET应用程序中直接在编辑模式下显示详细信息视图
In ASP.NET applications, when clicking a record in a List View, a Detail View is displayed in view mode. However, the SwitchToEditMode Action is available, and you can use it to reload the Detail View in edit mode. This is the default behavior. In individual scenarios, you may need to invoke a Detail View directly in edit mode. This topic demonstrates how to omit the display in view mode for a particular object type.
在ASP.NET应用程序中,单击列表视图中的记录时,在视图模式下显示详细信息视图。但是,"切换到编辑模式"操作可用,您可以使用它以编辑模式重新加载详细信息视图。这是默认行为。在个别方案中,您可能需要直接在编辑模式下调用"详细信息视图"。本主题演示如何省略特定对象类型的视图模式下的显示。
To set a Detail View's display mode, use the DetailView.ViewEditMode property. To change this property value, implement a View Controller and override the OnActivated method.
要设置详细视图的显示模式,请使用"明细视图.ViewEditMode"属性。要更改此属性值,实现视图控制器并重写 OnAndonon 方法。
using DevExpress.ExpressApp.Editors; //... public class SwitchToEditModeModificationsController : ViewController<DetailView> { protected override void OnActivated() { base.OnActivated(); if (View.ViewEditMode == ViewEditMode.View) { View.ViewEditMode = ViewEditMode.Edit; ObjectSpace.SetModified(null); } } }
To accomplish the implemented code when the current View represents an object of a particular type, set the ViewController.TargetObjectType property to this type in the View Controller's constructor. As an example, assume that the Controller is intended for Person type objects.
要在当前视图表示特定类型的对象时完成实现的代码,请将 ViewController.TargetObjectType 属性设置为视图控制器的构造函数中的此类型。例如,假设控制器适用于 Person 类型对象。
public SwitchToEditModeModificationsController() { TargetObjectType = typeof(Person); }
If you now run the application, you will see that the Person Detail View is always displayed in edit mode.
如果现在运行该应用程序,您将看到"人员详细信息"视图始终以编辑模式显示。
Note 注意
The View Controller demonstrated in this topic should be implemented in an ASP.NET module. In Windows Forms applications, Detail Views are always editable.
本主题中演示的视图控制器应在ASP.NET模块中实现。在 Windows 窗体应用程序中,详细信息视图始终可编辑。
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端