ASP.NET 动态数据和上传文件

发布于 2024-09-08 08:55:01 字数 468 浏览 8 评论 0原文

我正在开发一个小型的仅供内部使用的 Web 应用程序。鉴于其简单性和目标受众,我认为这可能是使用 ASP.NET 动态数据项目快速启动和运行的好机会。到目前为止一切顺利,除了一个问题让我重新考虑整个计划:

我需要能够通过网站上传文件。模型中有一个实体代表上传的文件。该实体具有文件内容、文件名和文件内容类型的属性。上传文件时,所有这些值均从单个 FileUpload 控件获取。

由于 FieldTemplate 与实体属性具有一对一关联,因此我决定需要为 File 实体创建一个自定义 EntityTemplate。此时,我已经为具有 FileUpload 控件的实体创建了一个“编辑”模板。我无法弄清楚的是,当用户单击“更新”链接时,如何将 FileUpload 控件中的数据返回到实体中并(最终)返回到数据库中。

非常感谢任何建议或指导。

I am developing a small, internal-use only web application. Given its simple nature and intended audience, I decided that it might be a good opportunity to use a ASP.NET Dynamic Data project to get things up-and-running quickly. So far so good, except for one issue that has me reconsidering the whole plan:

I need to be able to upload files through the website. There is an entity in the model that represents an uploaded file. This entity has properties for the file's contents, the file name, and the file's content type. When uploading a file, all of these values are obtained from a single FileUpload control.

Since a FieldTemplate has a one-to-one association with an entity property, I decided that I needed to create a custom EntityTemplate for the File entity. At this point, I have created an "edit" template for the entity that has a FileUpload control. What I have not been able to figure out is, when the user clicks the 'Update' link, how do I get the data from the FileUpload control back into the entity and (ultimately) into the database.

Any advice or guidance is much appreciated.

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

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

发布评论

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

评论(1

撩人痒 2024-09-15 08:55:01

您可以在 FiedlTemplate 的 ExtractValues 方法中向字典中添加其他值,您需要注意的是,如果这些值也在页面模板中显示为行或列,那么它们将覆盖您添加的值。我通常将它们设置为 false,然后仅在自定义字段模板中引用它们。

请注意,您可以从 OnDataBinding 事件中的 Row 属性访问它们的初始值,您可以将该属性强制转换为实际类型或使用通过伙伴类添加的接口。

you can add other values to the dictionary in the ExtractValues method of the FiedlTemplate, what you have to be aware of is that if those values also appear as rows or column in the page template then they will overwrite the values you added. I usually scaffold them as false and then only referance them in the custom field template.

Note you can access their initial values from the Row property in the OnDataBinding event, you can cast the property as the actual type or use an interface added via buddy classes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文