私はajaxとmvcを初めて使用します...jqueryからのデータのポストバックに問題があります。私が抱えている問題は、値が入力されていることです。コントローラーがヒットし、データベースが更新されてから、古いデータのページに戻ります。更新されていません。f5をクリックして、変更を確認する必要があります。何が間違っているのでしょうか。前もって感謝します
Jquery
var values =
{
"PagePartIdentifier": element,
"PagePartContent": data
}
$.post(@Html.Raw(Json.Encode(Url.Action("UploadData", "Home"))),values,function(data)
{
// do stuff;
});
モデル
public class PagePartModel
{
public string PagePartIdentifier { get; set; }
public string PagePartContent { get; set; }
}
コントローラ
[HttpPost, ValidateInput(false)]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult UploadData(PagePartModel pagePartm)
{
UpdatePage(pagePartm);
ModelState.Clear();
//return RedirectToAction("Index");
return Json(new { success = true });
}
Htmlはヘルパーメソッドからレンダリングされます
public static PagePartModel PageAfterContent(this System.Web.Mvc.HtmlHelper html, int page)
{
string part = "AfterContent";
Blog.PageParts pageParts = new Blog.PageParts();
PagePartModel thispart = pageParts.GetContentForPageByPart(page, part);
return thispart;
}
各パーツのモデルをページに返します