MVC FromUri&%3B

时间:2014-07-17 08:09:19

标签: c# asp.net-mvc url datamodel

在控制器上我有以下

Index([FromUri] SearchDataModel Search)

工作正常。但现在我得到一个这样的网址:

  

https://mysite.com/?SearchName=Test&amp%3Bvalue1=value1&amp%3Bvalue2=value2&amp%3Bvalue3=value3

我需要支持此网址,但由于放大器%3B,我无法获取参数 我尝试在我的模型中使用HttpUtility.UrlDecode(value);,但它不起作用......

请问任何建议?

1 个答案:

答案 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);
    }
}