1. 程式人生 > >mvc部分檢視

mvc部分檢視

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>

 

專案目錄:

 

 

 執行: