【发布时间】:2011-07-26 16:19:45
【问题描述】:
我有这个控制器
public ActionResult Index()
{
IList<Partner> p = r.ListPartners();
ViewBag.Partners = new SelectList(p.AsEnumerable(), "PartnerID", "Name");
return View();
}
//
// POST: /Epub/
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload)
{
IList<Partner> p = r.ListPartners();
ViewBag.Partners = new SelectList(p.AsEnumerable(), "PartnerID", "Name");
int count = 0;
for (int i = 0; i < fileUpload.Count(); i++)
{
if (fileUpload.ElementAt(i) != null)
{
count++;
var file = fileUpload.ElementAt(i);
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
// need to modify this for saving the files to the server
var path = Path.Combine(Server.MapPath("/App_Data/uploads"), Guid.NewGuid() + "-" + fileName);
file.SaveAs(path);
}
}
}
if (count == 0)
{
ModelState.AddModelError("", "You must upload at least one file!");
}
return View();
}
以及对应的视图
@{
ViewBag.Title = "Index";
}
<h2>You are in the epub portal!</h2>
@Html.Partial("_Download")
@model IEnumerable<EpubsLibrary.Models.Partner>
@{
@Html.DropDownList("PartnerID", (IEnumerable<SelectListItem>)ViewBag.Partners)
}
我试图弄清楚如何将选定的 PartnerID 从视图传递回控制器。任何指针将不胜感激。我查看了其他帖子,但似乎找不到可以帮助解决此问题的解决方案。
提前感谢您的宝贵时间。
【问题讨论】:
标签: c# asp.net-mvc-3