リダイレクト(または同等のもの)を呼び出すコントローラメソッド内のビューを更新するにはどうすればよいですか?RedirectToActionを呼び出すビューを更新するにはどうすればよいですか?
ビュー(Index.cshtml):
@model ViewModel
@Html.EditorFor(model => model.First)
@Html.EditorFor(model => model.Last)
@Html.EditorFor(model => model.Junk)
// call is invoked to PerformMagic as such:
onComplete: function (event, queueID, fileObj, response, data)
{
$.ajax(
{ url: '@Url.Action("PerformMagic","Home")',
data: { first: $("#fname").val() },
})
}
Junk.cshtml(編集テンプレート)
@model Models.Junk
<div>
@Html.LabelFor(model => model.ID)
@Html.EditorFor(model => model.ID)
</div>
<div>
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
コントローラー:
// Called from jquery client
public string PerformMagic(string Id)
{
ViewModel model = dbContext.GetPersistedView();
model.Junk.Add(new junk);
// I need to update my view here but this doesn't update the view (model updates fine)....
// ...after a refresh on the browser of course the new junk in the model is displayed.
return RedirectToAction("Index", model);
}
は_ _「これが動作しない」あなたは何を言うことができるか、あなたがすべきことは、モデルのJSON値を返し、クライアント側でページを更新しています動作しませんか?何が起こるのですか?あなたは 'ajax'リクエストでこのActionに到達しますか? – gdoron
@gdoron:更新を参照してください... – JaJ
Yessss。私は正しい...下の私の答えを参照してください。私のクリスタルボールは魅力のように機能します! – gdoron