我想知道如何使用RedirectToAction()传递字符串参数。
假设我有以下路由:
假设我有以下路由:
routes.MapRoute(
"MyRoute",
"SomeController/SomeAction/{id}/{MyString}",
new { controller = "SomeController", action = "SomeAction", id = 0, MyString = UrlParameter.Optional }
);
在SomeController中,我有一个执行重定向的操作,如下所示:
return RedirectToAction( "SomeAction", new { id = 23, MyString = someString } );
我尝试着使用 someString = "!@#$%?&* 1" 进行重定向,无论是否对其进行编码都会失败。我已经尝试使用 HttpUtility.UrlEncode(someString)、HttpUtility.UrlPathEncode(someString) 和 Uri.EscapeUriString(someString) 进行编码,但都没有成功。
因此,我使用 TempData 来传递 someString,但仍然很好奇如何使上述代码能够正常工作,只是为了满足我的好奇心。
web.config
中更改relaxedUrlToFileSystemMapping
和requestPathInvalidCharacters
吗? - Eric Yin