我有一個MVC項目,我在這張表格裏發佈了一個CommentController裏的方法(Create)。我使用的是httppost。代碼如下所示: 包含表單的視圖。MVC Post form data using Ajax and GET
@model myproject.Models.Comment
@using (Ajax.BeginForm("Create",
new AjaxOptions { UpdateTargetId = "CommentContainer" }))
{
@Html.ValidationSummary(true)
@Html.LabelFor(model => model.UserComment)
@Html.EditorFor(model => model.UserComment)
@Html.ValidationMessageFor(model => model.UserComment)
<br />
<input type="submit" value="Create comment" />
}
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js"></script>
的CommentController包含創建方法
[HttpPost]
public PartialViewResult Create(Comment comment)
{
return PartialView("_RandomComment", comment);
}
現在,這一切工作正常,但我要的是要做到這一切使用GET無法發佈。我仍然想使用Ajax.BeginForm和2個JavaScript庫。我不想寫我自己的jQuery代碼。如何將上面的表單數據發佈到我的CommentController中的GET方法中。
爲什麼要使用GET進行POST數據? – Maess
以避免用戶單擊瀏覽器上的後退按鈕時的回發警告。 – Ovis