0

HttpPostをキャッチしているとき、別のResultActionにリダイレクトしています。これは私のint値を保持していますが、リスト値は保持していません。理由がわからないようです。ページ番号=2、searchAction = 3、clearanceResults(リスト)の25項目の投稿を取得した場合。投稿に期待する内容が返されますが、Details ActionResultに到達すると、pageNumberとsearchActionのみが保持され、clearanceResultsのリストは保持されません。奇妙なことに、リストはnullではなく、カウントが0になっています。

モデル:

public class ClearanceListViewModel
{
    public ClearanceListViewModel()
    {
        this.pageNumber = 1;
        this.searchAction = 1;
        this.lastPage = false;
    }

    public ClearanceListViewModel(int pageNumber, int searchAction)
    {
        this.pageNumber = pageNumber;
        this.searchAction = searchAction;            
    }

    public int pageNumber { get; set; }
    public int searchAction { get; set; }
    public List<ClearanceViewModel> clearanceResults { get; set; }
    public bool lastPage { get; set; }
}

コントローラに投稿する:

    [HttpPost]
    public ActionResult Details(ClearanceListViewModel model, FormCollection collection)
    {
        ClearanceListViewModel cModel = new ClearanceListViewModel();
        cModel = model;
        cModel.clearanceResults = model.clearanceResults;
        // do something
        return RedirectToAction("Details", cModel);
    }

コントローラでのアクション結果:

public ActionResult Details(ClearanceListViewModel model)
    {

        DataTable dt = new DataTable();
        List<ClearanceViewModel> clearanceList = new List<ClearanceViewModel>();

        //save any changes
        if (model.clearanceResults != null)
        {
            ClearanceSave(model);
            model.clearanceResults = null;
        }

        string inQuery = "select sku, qty from products";

        // call the query
        dt = AS400DAL.Instance.ExecuteQueryAsDataTable(inQuery);

        model = Utility.Utility.ProcessClearanceSkus(dt, model);
        return View("Index",model);
    }

任意の入力をいただければ幸いです。

ありがとう!

4

2 に答える 2

2

の過負荷を調べRedirectToActionます。モデルの通過を許可するものはありません。通常、投稿はデータベースを変更し、データベースからモデルを再作成するアクションにリダイレクトします。リダイレクトはクライアントで発生するものであるため、リダイレクトされたリクエストはリダイレクトを発行した投稿とは完全に分離されているため、モデルは永続化されません。

于 2013-01-08T16:19:37.503 に答える
0

セッションを使用してモデルを保存し、

できるよ:

Session["mymodel"] = model;

次に、リダイレクト後にセッションからモデルを取得します

ClearanceListViewModel newModel = (ClearanceListViewModel)Session["mymodel"];

これにより、モデルを正常に渡すことができます

于 2013-01-08T16:23:58.767 に答える