ASP.NET MVC2 in Action 读书笔记 [9-1] ChildAction

1). ChildAction

HomeController.cs:

[HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
 
            return View();
        }
 
        [ChildActionOnly]
        public ActionResult ChildAction()
        {
            return View();
        }
    }

Index.aspx:

<h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>
    <%Html.RenderAction("ChildAction"); %>

ChildAction.aspx:

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
 
<h2>This view was rendered by calling RenderAction. This is a ChildAction</h2>
 

你可能感兴趣的:(asp.net)