Home控制器:
public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult PartialPage(string name, int id) { ViewBag.id = id; ViewBag.name = name; return View("~/Views/Shared/PartialPage.cshtml"); } }
Index视图:
@Html.Action("PartialPage", "Home", new { name = "SharpL", id = 1 }) <p>原视图中的p元素</p>
在Views下的Shared下新建部分PartialPage视图:
<p>我是分部视图</p> <p>博客名为:@ViewBag.name</p> <p>博客的id为:@ViewBag.id</p>
项目目录:
运行: