MVC3 路由 - href 添加了其他路由



>我有一个html助手:actionLink,它在"a href"中生成一个"img"

所以这个:

Html.ActionImage"Create", "Premises", "~/Images/Views/Premises/LicensableActivitiesButton.png", "Licensable Activities", new { id = "licensableActivitiesImg" })</div>

生成这个:

<a id="licensableActivitiesImg" href="/Users/Premises/Create"><img src="/Images/Views/Premises/LicensableActivitiesButton.png" alt="Licensable Activities">

问题是它将"/Users/"附加到 href 的开头,我不知道为什么。 这个附加也发生在我的开始表单中:

using (@Html.BeginForm("Create", "Premises", FormMethod.Post, new { id = "premisesForm" })) 

给:

<form id="premisesForm" method="post" action="/Users/Premises/Create">

我的路线很简单:

       routes.MapRoute(
             "",
             "Premises/Premises/Create",
             new { controller = "Premises", action = "Create" }
             );

        routes.MapRoute("Default", // Route name                
                        "{controller}/{action}/{id}", // URL with parameters                
                        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults            
                       );

区域未被使用。

HTML 帮助程序代码:

    public static MvcHtmlString ActionImage(this HtmlHelper html, string action, string 
     Controller, string imagePath, string altText, object htmlAttributes, object routeValues)
    {
        var url = new UrlHelper(html.ViewContext.RequestContext);
        // build the <img> tag 
        var imgBuilder = new TagBuilder("img");
        imgBuilder.MergeAttribute("src", url.Content(imagePath));
        imgBuilder.MergeAttribute("alt", altText);
        string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);
        // build the <a> tag 
        var anchorBuilder = new TagBuilder("a");
        anchorBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
        anchorBuilder.MergeAttribute("href", url.Action(action, controller, routeValues));
        anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside 
        string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);
        return MvcHtmlString.Create(anchorHtml);
    }

任何想法/建议不胜感激。

好的,经过几个小时的沮丧,我发现断点没有被命中。

原来正在加载旧程序集。

检查构建设置:项目 -> 属性 -> 构建选项卡

生成输出路径设置为:/bin/x86/调试

将其更改为:/bin

并命中断点,href 显示正确的路径。

唷!

最新更新