Как просмотреть файл после загрузки его к App_Data/Uploads в MVC 3 с Бритвой?

я плохо знаком с 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" />
}

Для моего контроллера, я использую этот

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 = Path.GetFileName(file.FileName);
        // store the file inside ~/App_Data/uploads folder
        var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
        file.SaveAs(path);
    }
    // redirect back to the index action to show the form once again
    return RedirectToAction("Index");        
  }
} 

, Моя модель

public class FileDescription
{
    public int FileDescriptionId { get; set; }
    public string Name { get; set; }
    public string WebPath { get; set; }
    public long Size { get; set; }
    public DateTime DateCreated { get; set; }
}

, вещь, я хочу загрузить файл на базу данных и затем WebPath, чтобы быть ссылкой с моим файлом. Я надеюсь, что ясно выразился достаточно. Любая справка действительно ценилась бы. Спасибо

5
задан Major Byte 4 September 2011 в 22:16
поделиться