所以我不知道這裏發生了什麼。我有這種模式彈出窗口,從一個動作加載部分視圖(這可能是問題??)。部分視圖加載完美並且流程正常,但是一旦帖子結束並且應該返回一個json,而不是僅僅關閉然後發佈結果的模式,它會將我重定向到另一個顯示json結果(而不是局部視圖)的頁面。我不完全確定我接近這個方式是否正確。我只需要在動作成功處理後關閉對話框,然後在保存事務或拋出錯誤時返回消息。mvc c#與jquery getjson不關閉模式彈出窗口,但重定向到與json結果的另一頁
任何意見表示讚賞。謝謝!!!該大幹快上彈出
<% using (Html.BeginForm("New", "Registration", FormMethod.Post, new { id = "new-registration" })){ %>
<h2>Register Participant:</h2>
<div class="">
<%: Html.ValidationSummary(null, new { @class = "" })%>
<div class="">
<div class="">Email Address:</div>
<div class="">
<%: Html.TextBox("Email", null, new { @class = "" })%>
</div>
</div>
<button type="submit" value="Submit">Register</button>
</div>
<% } %>
行動
public ActionResult New(){
return PartialView(context.Contest.FirstOrDefault(e => e.Id == 1));
}
[HttpPost]
public ActionResult New(FormCollection formCollection)
{
string email = formCollection["Email"].ToString();
try
{
if (email == "")
throw new Exception("Please provide an email address.");
Registration registration = new Registration
{
ContestId = 1,
Email = email
};
context.Registration.Add(registration);
context.SaveChanges();
return Json(new { success = "true", message = "User succesfully registered to Contest." });
}
catch (Exception ex)
{
//throw ex;
return Json(new { success = "false", message = ex.Message });
}
}
你可能會想檢查[這](http://yassershaikh.com/how-to-create-a-modal-popup-in-asp-net-mvc-3-using-jquery/) – Yasser 2012-08-08 05:22:05