[MVC 4随机值添加到URL

问题描述 投票:0回答:1

出于某些原因,我的MVC 4应用程序的所有URL上,应用程序似乎都在URL末尾添加了随机锚值,例如#.Uhz_BdLbNz4,但我不知道为什么。我敢肯定,这很简单,但它使我发疯,我在网上找不到任何有关它的信息。

有人知道这是什么以及如何摆脱它吗?

欢呼声

丹尼

更新:根据要求,我的路由配置只是下面的标准配置]

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

示例链接:

    <a href="@Url.Action("Sessions", "Training", new { Month=DateTime.Now})">Find a Session >></a>

最后是生成HTML的示例:

    <ul class="top-nav cg-22-white">
        <li class="first-item"><a href="/">Home</a></li>
        <li><a href="/news">News</a></li>
        <li><a href="/mercedes/about">About Mercedes</a></li>
        <li><a href="/contactus">Contact Us</a></li>
        <li><a href="/blog">Blog</a></li>
    </ul>

<a href="/Training/Sessions?Month=08%2F27%2F2013%2020%3A44%3A44">Find a Session >></a>
asp.net-mvc url asp.net-mvc-4 random
1个回答
1
投票
<a href="/Training/Sessions?Month=08%2F27%2F2013%2020%3A44%3A44">Find a Session >></a>

生成的url末尾的值不是随机的,它是DateTime.Now对象的字符串表示形式,您已在Url.Action-Helper中的匿名对象中插入了该对象。如果您没有发送该参数,则只需删除Url.Action的匿名对象

PS:如果在名为month的操作上具有DateTime参数,则应为您自动绑定该参数。

© www.soinside.com 2019 - 2024. All rights reserved.