【发布时间】:2014-07-14 16:54:10
【问题描述】:
我有一个使用 MVC 4 和实体框架的 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 似乎都构建不正确并且没有刷新中心内容。有人知道为什么会这样吗?
【问题讨论】:
-
对于初学者,您发出的 HTML 格式非常错误。您的内容视图应该只是页面的 content,而不是整个页面结构。将 html/head/body 标签放在
div中可能会使浏览器感到困惑。至于您看到的实际问题,这些操作链接呈现的结果锚标记是什么?是否有任何 JavaScript 覆盖了他们的点击事件? -
@David 没有什么可以覆盖点击事件。我之所以使用整页是因为我认为使用 Razor 和 cshtml 需要整页设计。我可以像您建议的那样将其设计为部分页面吗?呈现的锚标签如下:
<a class="basiclink" href="/?Length=4">Home</a><a class="basiclink" href="/?Length=17">System Information</a>
标签: asp.net entity-framework asp.net-mvc-4 razor