如何创建 ASP.NET MVC 控制器操作以便它们接受文件?
我整个周末都在为我的网站开发消息系统,以便用户可以在我的网站内部发送和接收消息。
我已经制定了表模式,现在我可以向不同的用户发送基本消息。
现在,我正在处理附件部分。
如何创建我的操作方法以便它们接受文件?理想情况下,我希望允许控制器操作接受任意数量的文件。一旦它们被传递到控制器操作中,我将把它们保存在我的网络服务器上的某个地方。
谁能向我展示一个接受文件作为其参数一部分的控制器操作的示例?
I've been working all weekend on a Messaging system for my website so users can send and receive messages on my site internally.
I have my table schemas worked out, and right now I can send basic messages to different users.
Now, I'm working on the attachments portion.
How can I create my action methods so that they accept Files? Ideally I would like to allow for a controller action that accepts an arbitrary number of files. Once they have been passed into the controller action I'm going to save them somewhere on my webserver.
Can anyone show me an example of a controller action that accepts files as part of its parameters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
(错误处理省略。)
(Error handling omitted.)
我相信您正在寻找的对象是下面的
Request.Files
示例片段。I believe the object you're looking for is
Request.Files
example snippet below.这是一篇关于如何使用 ASP.NET MVC 上传文件的文章
Here is a post on how to Upload file with ASP.NET MVC
查看我在这篇文章中的回答。
调用控制器 post 方法时遇到问题
Check out my answer in this post.
Having troubles calling a controller post method