在运行时为操作方法创建适当的参数?
情况是这样的。
我有一个操作方法,它返回一个文件,在“文档”控制器中称为“GetDocument”。它有一个文档类型的参数,其中包含文档路径、标题、类型等。
我有一个实体的视图,其中附加了一些文档。例如,带有附加文档的新闻报道。在此视图中,我显示了最终用户应该能够下载的文档的各种链接。
问题是:如何创建这样的链接,将正确的“Document”对象传递给“GetDocument”操作方法?
编辑:我不想向用户显示文档的完整路径。事实上,我希望将文档存储在 App_Data 文件夹中,这样就无法下载它们。
谢谢!
Here is the situation.
I have an action method, which returns a file, called "GetDocument" in "Documents" controller. It has one parameter of type Document, which contains document path, title, type etc.
I have a View for an entity, which has some documents attached with it. For example, a news story, with attached documents. On this view I show various links for the documents which the end user should be able to download.
The question is: How do I create such links which pass proper "Document" object to the "GetDocument" Action Method?
Edit: I do not want to show full path of the document to the user. In fact, I would like that I store documents in App_Data folder, so that they cannot be downloaded otherwise.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
ActionLink
:然后:
You could use an
ActionLink
:and then:
为什么在调用操作时您的控制器需要了解完整文档?你的文档肯定有 ID。获取 id,向存储库询问域对象,然后获取文件。
why would your controller need to know about the full document when the action is called? surely your documents have ids. take the id, ask your repository for the domain object, and then get the file.