在asp.net MVC中传递多个查询字符串值

时间:2016-12-01 13:49:29

标签: asp.net-mvc asp.net-mvc-4 c#-4.0 routes

Routeconfig中有以下路线

routes.MapRoute(
                name: "WithParams",
                url: "{controller}/{action}/{langue}/{AffID} ",
                defaults: new { controller = "Home", action = "Index", AffId = "", langue = "" }
            );

我试图从系统的某个部分调用此路线。

Response.RedirectToRoutePermanent("WithParams", new RouteValueDictionary { AffId :123,langue:"EN" });

它给出了语法错误,我们如何在上面的重定向中传递查询字符串参数。

2 个答案:

答案 0 :(得分:0)

试试这个:

return RedirectToRoutePermanent("WithParams", new { AffId = 123, langue = "EN" });

答案 1 :(得分:0)

试试这个:

  Dictionary<string,string> dictionary = new Dictionary<string, string>();
        dictionary.Add("AffId", "58");
        dictionary.Add("langue", "EN");


        Response.RedirectToRoutePermanent("WithParams", new RouteValueDictionary(dictionary));