0

この投稿アクションは、ajax jquery ダイアログから呼び出されます。

テンプレートを選択すると、RedirectToAction メソッドを実行する必要がありますが、UnitController と GetTemplateRootUnits アクションはヒットしませんか?

私は何を間違っていますか?

   [HttpPost]
    public ActionResult Open(int selectedTemplateId)
    {
     if (ModelState.IsValid)
     {

     return RedirectToAction("GetTemplateRootUnits", "Unit", new { TemplateId = selectedTemplateId });

     }
     else
     {
         return LoadOpenTemplates();
     }          
    }

私のルートテーブル:

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
            );

呼び出すターゲットコントローラー/アクション:

[HttpGet]
public JsonNetResult GetTemplateRootUnits(int templateId)
{
 IEnumerable<Unit> units = _unitDataProvider.GetTemplateRootUnits(templateId);
 return new JsonNetResult(new { data = units });
}

 function openTemplate(dlg, form) {
        $.ajax({
            url: $(form).attr('action'),
            type: 'POST',
            data: form.serialize(),
            success: function (response) {
                if (response.success) {
                    dlg.dialog("close");
                    $('#TreeDiv').empty();
                    loadUnits(response.data);
                }
                else {  // Reload the dialog with the form to show model/validation errors                    
                    dlg.html(response);
                }
            }
        });
    }
4

1 に答える 1

1

RedirectToActionAJAX POST を使用すると機能しません。以下を参照してください。

RedirectToAction が機能しない

この場合、リダイレクトするには JavaScript を使用する必要があります。

いくつかのアプローチ:

jQuery Ajax 呼び出し後のリダイレクト要求を管理する方法

RedirectToAction がリダイレクトしない

于 2012-08-22T23:17:23.187 に答える