2017-06-06 13 views
1

ビューへのリダイレクトに関連するその他の質問を見てきましたが、問題を修正するものはありません。私はCreateアクションに仲介するステップがあり、そのステップのビューからCreateビューにリダイレクトすることはできません。私の実際のコードの近似値は次のとおりです。ASP.NET MVC - 作成アクションにリダイレクトできません

public ActionResult SelectDependancy() 
{ 
    ViewBag.ProductID = new SelectList(db.Products, "ID", "Name"); 
    ViewBag.ComponentID = new SelectList(db.Components, "ID", "Name"); 
    return View(); 
} 

このアクションのビューはSelectDependancy(string, string)への呼び出しになりPOSTメソッドを持っています。

このPOSTは、AJAX POSTがreturn RedirectToAction("Create");が動作していないよう

[HttpPost] 
[ValidateAntiForgeryToken] 
public void SelectDependancy(string ProductID, string ComponentID) 
{ 
    FilteredCreate(ProductID, ComponentID); 
} 

private ActionResult FilteredCreate(string ProductID, string ComponentID) 
{ 
    //Filter values based on ProductID + ComponentID 

    return RedirectToAction("Create"); 
} 

JS標準POSTではありません。私もreturn View("Create")に変更しようとしました(メソッドの戻り値の型を変更する)

+0

「作成」アクションへのリダイレクトは「うまくいかない」とはどうでしょうか?どのように具体的に失敗していますか?あなたの最後のコードスニペットでは、 'SelectDependancy'アクションは* anything *を返さないので、あなたが何をしているのかは分かりません。 – David

+0

FilteredCreateを使用する理由はありますか? –

+1

'public void SelectDependancy'を' public ActionResult SelectDependancy'に変更します。そして、メソッド 'return FilteredCreate(ProductID、ComponentID);の中で – adiga

答えて

2

SelectDependancyからActionResultをリダイレクトする必要があります。

[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult SelectDependancy(string ProductID, string ComponentID) 
{ 
    return FilteredCreate(ProductID, ComponentID); 
} 
関連する問題