如何在MVC 4中的数据库中获取上传的文件名 [英] How to Get Uploaded File name in Database In MVC 4
本文介绍了如何在MVC 4中的数据库中获取上传的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用此控制器上传文件
I have uploaded file by using this controller
[HttpPost]
public ActionResult Create(AdulLiteracyTeachers adulliteracyteachers, HttpPostedFileBase[] files)
{
foreach (HttpPostedFileBase file in files)
{
string path = System.IO.Path.Combine(Server.MapPath("~/App_Data"), System.IO.Path.GetFileName(file.FileName));
file.SaveAs(path);
}
if (ModelState.IsValid)
{
db.AdulLiteracyTeachers.Add(adulliteracyteachers);
db.SaveChanges();
return RedirectToAction("Index");
}
视图是:
the view is :
using (Html.BeginForm("Create", "AdultLiteracyTeachers", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<label for="file">Upload Image:</label>
<input type="file" name="files" value="" multiple="multiple"/>
<input name="Upload" type="submit" value="Create" />
当我打开特定记录如何用名称生成图片时,我想在数据库中保存文件名吗?
实际上我更重视学生姓名,Rollno [key]和iam没有使用任何图像propety在模型中。如何使用这个,当我想看到数据如何通过路径Rtirive特定图像
I want to save the file name in database when i open the specifc record how the picture is generated with name ?
Actually I ahve more values student name , Rollno[key] and iam not using any image propety in model . How to use this and when I wnat to see the data how Can i Rtirive by path the specific image
推荐答案
这篇关于如何在MVC 4中的数据库中获取上传的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文