我有一个使用MVC 4和Entity Framework的ASP.NET项目,结构如下:
-Controllers
-HomeController.cs
-SystemInformationController.cs
-Views
-Home
-Index.cshtml
-Shared
-MasterLayout.cshtml
-SystemInformation
-Index.cshtml
MasterLayout.cshtml代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Sample Site</title>
<link href="~/Content/MasterPage.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="TopContent">
<a>Home</a>
</div>
<div id="LeftContent">
@Html.ActionLink("Home", "Index", "Home", new { @class = "basiclink" })
<br />
@Html.ActionLink("System Information", "Index", "SystemInformation", new { @class = "basiclink" })
<br />
</div>
<div id="MainContent">
@RenderBody()
</div>
Home视图的Index.cshtml代码如下:
@{
Layout = "~/Views/Shared/MasterLayout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Home Page</title>
</head>
<body>
<div>
Welcome to the Sample Site.
</div>
</body>
</html>
我遇到的问题是每当我点击任一链接时,无论是主链接还是系统信息链接,网址都会附加一个“?length = X”,其中X是第三个参数的长度。 ActionLink项目。我希望刷新母版页内的内容,但无论我做什么,URL似乎都是错误构建的,而不是刷新中心内容。任何人都有任何想法,为什么会发生这种情况?
答案 0 :(得分:2)
问题是你使用的ActionLink方法的重载超出了你可能想要的。您正在使用的是获取第三个参数并将其用作路径值,而不是控制器名称。尝试更改您的链接:
@Html.ActionLink("Home", "Index", "Home", new {}, new { @class = "basiclink" })