Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - How to pass List in Redirecttoaction

I want to pass more then one parameter from RedirectToAction method

how can I pass?

My One Action Method

 [HttpPost, ActionName("SelectQuestion")]
    public ActionResult SelectQuestion(string email,List<QuestionClass.Tabelfields> model)
    {

        List<QuestionClass.Tabelfields> fadd = new List<QuestionClass.Tabelfields>();
        for (int i = 0; i < model.Count; i++)
        {
            if (model[i].SelectedCheckbox == true)
            {
                List<QuestionClass.Tabelfields> f = new List<QuestionClass.Tabelfields>();
                fadd.Add(model[i]);
            }
        }

        return RedirectToAction("Question", new { email = email, model = fadd.ToList() });
    }

My another Action Method

    [HttpGet]
    public ActionResult Question(string email,List<QuestionClass.Tabelfields> model)
    {
    }

I am not getting values in model.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot pass a collection of complex objects in urls when redirecting.

One possibility would be to use TempData:

TempData["list"] = fadd.ToList();
return RedirectToAction("Question", new { email = email});

and then inside the Question action:

var model = TempData["list"] as List<QuestionClass.Tablefields>;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...