我正在学习ASP.NET MVC,并试图让我的头部部分视图。我正在尝试一个非常简单的事情,这里是我的源代码。部分视图覆盖主视图
_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
@RenderBody()
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
_ViewStart.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication4.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public PartialViewResult UpdateDate()
{
return PartialView("Partial1");
}
}
}
Index.cshtml
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@DateTime.Now
<br />
@{Html.RenderPartial("Partial1");}
<br />
@Html.ActionLink("Render Partial", "UpdateDate")
Partial1.cshtml
@DateTime.Now
现在,当我点击渲染部分链接UpdateDate动作方法被调用,但渲染局部视图覆盖的主要内容,我只看到局部视图的内容。为什么我会丢失Index.cshtml的内容?
我需要做什么才能显示Index.cshtml的内容,并且仅显示部分视图内容?
感谢您的解释。 – user2265934 2013-04-10 12:49:51