小编Maj*_*yte的帖子

如何使用Razor将文件上传到MVC 3中的App_Data/Uploads后查看文件?

我是mvc的新手,我遇到了问题.我搜遍了所有的答案,我找不到一个,但我很确定有些东西会让我失望.问题是我在将文件上传到App_Data文件夹后不知道如何访问文件.我使用在所有论坛上找到的相同代码:

对于我的观点,我使用它

@using (Html.BeginForm("Index", "Home", FormMethod.Post, 
new { enctype="multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="submit" />
}
Run Code Online (Sandbox Code Playgroud)

对于我的控制器,我使用它

public class HomeController : Controller
{
// This action renders the form
public ActionResult Index()
{
    return View();
}

// This action handles the form POST and the upload
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
    // Verify that the user selected a file
    if (file != null && file.ContentLength > 0) 
    {
        // extract only the fielname
        var fileName …
Run Code Online (Sandbox Code Playgroud)

c# file-upload view razor asp.net-mvc-3

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

asp.net-mvc-3 ×1

c# ×1

file-upload ×1

razor ×1

view ×1