在控制器上我有以下
Index([FromUri] SearchDataModel Search)
工作正常。但现在我得到一个这样的网址:
https://mysite.com/?SearchName=Test&%3Bvalue1=value1&%3Bvalue2=value2&%3Bvalue3=value3
我需要支持此网址,但由于放大器%3B,我无法获取参数
我尝试在我的模型中使用HttpUtility.UrlDecode(value);
,但它不起作用......
请问任何建议?
答案 0 :(得分:0)
不一样的情况,但也许有帮助......这就是,如何接受控制器名称中的连字符...
<强>路由:强>
var defaultRoute = routes.MapRoute(
"Default",
"{param}",
new { controller = "Home", action = "Index", param = UrlParameter.Optional }
);
defaultRoute.RouteHandler = new HyphenRouteHandler();
<强> HyphenRouteHandler:强>
public class HyphenRouteHandler : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
//here you can probably do your urlencoding
requestContext.RouteData.Values["controller"] = requestContext.RouteData.Values["controller"].ToString().Replace("-", "_");
requestContext.RouteData.Values["action"] = requestContext.RouteData.Values["action"].ToString().Replace("-", "_");
return base.GetHttpHandler(requestContext);
}
}