HTML HELPER Link
@Html.ActionLink("Link Text", "Edit", "StoreManager", new { id = 1 }, null) //名称,action,controller ,value,htmlattribute; // /StoreManager/Edit/1
@Html.RouteLink("Link Text", new { action = "Edit", id = 1 }) //...CurrentController/Edit/1
@Html.Action("Other", "StoreManager") @*直接显示页面的内容 整个页面包括header,body等元素*@ @Url.Action("Other", "StoreManager", new { name = "gen" }) @* 显示:/StoreManager/Other?name=gen*@
@Html.Partial("Other") @*The Partial helper renders a partial view into a string*@ @*RenderPartial writes directly to the response output stream instead of returning a string. For this reason, you must place RenderPartial inside a code block instead of a code expression *@ @{Html.RenderPartial("Other");}
//(either high site traffi c or repeated calls in a loop) before the difference would be noticeable.
public class MyController : Controller { public ActionResult Index() { return View(); } [ChildActionOnly] //recommand required public ActionResult Menu() { var menu = new List<string>() { "aaa","bbb","ccc" }; ViewBag.menu = menu; return PartialView(menu); } }
MyControll Menu view:
@{ ViewBag.Title = "Menu"; } <ul> @foreach (var item in ViewBag.menu) { <li>@item</li> } </ul> <h2>Menu</h2>
MyControll Index view:
@{ ViewBag.Title = "Index"; } @Html.Action("Menu") <h1>Welcome to the Index view</h1> <h2>Index</h2>
MyControll Index view will show the menu view.
浙公网安备 33010602011771号