我有这样的事情:
public ActionResult Create(int clubid)
{
var club = db.Clubs.Single(c=>c.Id == clubid);
ViewBag.Club = club;
Competition comp = db.Competitions.Create();
return View(comp)
}
在我的.cshtml中:
@Model Models.Competition
...
@Using(Html.BeginForm())
{
...
<input type="submit" value="Save" />
}
使用以下Post Action可以正常工作:
[HttpPost]
public ActionResult Create(Competition comp)
{
if (ModelState.IsValid){...}
return RedirectToAction(...);
}
但是,我想从
@ViewBag.Club
对象传递一个附加参数:[HttpPoSt]
public ActionResult Create(int clubid, Competition comp){...}
如何在
BeginForm
中对此进行编码? 最佳答案
这里有两个选择。
编辑
@Html.Hidden("clubid", ViewBag.Club.id)
要么
@using(Html.BeginForm("action", "controller",
new { clubid = @Viewbag.Club.id }, FormMethod.Post, null)