我正在关注 Adam Freeman 的这本书 Pro.ASP.NET.MVC.3.Framework。 所以我下载了代码并在他的菜单类别中生成了这个 html 代码。
HTML:
<a class="" href="/Chess%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20">Chess </a>
按下链接时的结果(显而易见):
http://localhost:43190/Chess%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20
我不知道有人对这本书有这个问题。
我在我的 global.asax 中尝试:
routes.IgnoreRoute("favicon.ico");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
在我的布局中:
<link rel="shortcut icon" href="@Url.Content( "~/Content/themes/base/images/favicon.ico" )" type="image/x-icon" />
在我的 ninject Controller 中:
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
if (controllerType != null)
{
return (IController)ninjectKernel.Get(controllerType);
}
else
{
return base.GetControllerInstance(requestContext, controllerType);
}
}
不知道有没有人和我有同样的问题。我该如何解决这个问题?
最佳答案
编辑: 真正的答案 好的,我知道我的 sql 是 nvarchar 所以它生成了空格,我更改为 varchar 并且知道不会生成空格
我在某处读到,添加 .trim() 就可以做到这一点,是的,它有效,我不明白为什么它放这个(%20%20%20%20%20%20%20%20%20%20%20 %20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20 %20%20%20%20%20%20%20%20%20)
为此更改此“类别 = 链接” “类别= link.Trim(),”
菜单.chtml
@model IEnumerable<string>
@{
Layout = null;
}
@Html.ActionLink("Home", "List", "Product")
@foreach (var link in Model)
{
@Html.RouteLink(link, new {
controller = "Product",
action = "List",
category = link.Trim(),
page = 1
}, new {@class = link == ViewBag.SelectedCategory ? "selected": null}
)
}
关于asp.net-mvc-3 - Adam Freeman 书中的 Pro.ASP.NET.MVC.3.Framework 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12132098/