發送在MVC3模型我有動作方法速率()的HttpPost和HTTPGET版本:使用html.beginform
http://pastebin.com/embed_js.php?i=6x0kTdK0
public ActionResult Rate(User user, Classified classified)
{
var model = new RatingModel
{
CurrentUser = user,
RatedClassified = classified,
};
return View(model);
}
[HttpPost]
public ActionResult Rate(RatingModel model)
{
model.RatedClassified.AddRating(model.CurrentUser, model.Rating);
return RedirectToAction("List");
}
該HTTPGET速率()返回的視圖:
@model WebUI.Models.RatingModel
@{
ViewBag.Title = "Rate";
}
Rate @Model.RatedClassified.Title
@using(Html.BeginForm("Rate","Classified", FormMethod.Post))
{
for (int i = 1; i < 6; i++)
{
Model.Rating = i;
<input type="submit" value="@i" model="@Model"></input>
}
}
我想通過表單發送一個模型到Post方法,我的想法是提交按鈕的標記中的值「模型」將是這樣做的參數,但是如果我在Post方法內斷點,則傳遞null。 for循環試圖創建5個按鈕來發送正確的評分。
感謝
HTTP:/ /stackoverflow.com/editing-help#code – SLaks 2012-03-12 01:47:22
pastebin鏈接不是SO上的代碼塊的好替代品。 – 2012-03-12 01:50:41