我在我看来,用这个:<input type="file" id="deploymentPackage" name="deploymentPackage" />
而在我的控制器中,我这样做:
public ActionResult AddRelease(ApplicationReleaseViewModel appRelease, HttpPostedFileBase deploymentPackage)
{
if (ModelState.IsValid)
{
ApplicationRelease dto = new ApplicationRelease();
appRelease.UpdateDto(dto);
using (StreamReader sr = new StreamReader(deploymentPackage.InputStream))
{
dto.DeploymentPackage = new byte[deploymentPackage.InputStream.Length];
deploymentPackage.InputStream.Read(dto.DeploymentPackage, 0, dto.DeploymentPackage.Length);
}
this.ApplicationService.AddApplicationRelease(dto);
return RedirectToAction("Index", new { ActionPerformed = "ApplicationReleaseAdded", Name = appRelease.Name.CutToMaxLength(50).UrlEncode() });
}
else
{
ViewBag.PostAction = "AddRelease";
return View("EditRelease", appRelease);
}
}
更新:看看这个链接,如果你不能从“我的”代码中抽象出你自己。
http://www.codeproject.com/KB/aspnet/Implementing_HTTP_File_Up.aspx
是什么ApplicationReleaseViewModel我看到这个第一次。任何特别的东西 – Adrian 2011-05-21 08:31:19
是的,那是我自己的特定视图/动作视图模型。不要注意这一点。 – MartinHN 2011-05-21 08:39:42
请问您可以为我重写代码 – Adrian 2011-05-21 08:57:39