如何在MVC中编码按钮上传文件 [英] How to code button Upload file in MVC
本文介绍了如何在MVC中编码按钮上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有模型类包含保存图像的字段
i想要按钮上传并保存在数据库中
该图像将显示在页面
解决方案
在表单中创建一个简单的HTML提交按钮,
< 表格 方法 = 发布 >
< 输入 type = file < span class =code-attribute> / >
< 输入 type = 提交 value = 上传 / >
< / form >
在此表单的后端,您可以执行代码以上载文件。在ASP.NET MVC中,您可以创建处理HttpPost请求的不同操作,
[HttpPost]
< span class =code-keyword> void UploadFile(UploadFileModel model){
// 上传文件的代码
}
这样,你可以触发函数来处理文件上传
i have model class contain field to Save Image
i want to make button upload and save in database
that image will be show in page
解决方案
Create a simple HTML submit button inside the form,
<form method="post"> <input type="file" /> <input type="submit" value="Upload" /> </form>
On the back-end of this form, you can execute the code to upload the file. In ASP.NET MVC, you can create different actions, that handle the HttpPost requests,
[HttpPost] void UploadFile(UploadFileModel model) { // code to upload the file }
This way, you can trigger the function to handle the file upload.
这篇关于如何在MVC中编码按钮上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文