我有这个控制器
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 从视图传递回控制器。任何指示将不胜感激。我看过其他帖子,但似乎找不到有助于解决此问题的解决方案。
在此先感谢您的时间。
您可以创建一个接受 FormCollection 参数的 ActionResult,以便从视图中的控件获取值,如下所示:
在填充列表的视图中:
<% using (Html.BeginForm("MyActionButton", "Home")) { %>
<%= Html.DropDownList("MyList",(SelectList)ViewData["testItems"], "None") %>
<input type="submit" value="send" />
<% } %>
在Server端获取值:
public ActionResult MyActionButton(FormCollection collection)
{
string value = collection["MyList"];
return View();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)