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>
 

相关文章:

  • 2021-06-29
  • 2021-10-28
  • 2022-01-05
  • 2022-12-23
  • 2021-07-20
  • 2022-02-03
  • 2022-02-14
  • 2021-09-25
猜你喜欢
  • 2021-07-10
  • 2022-01-30
  • 2021-10-17
  • 2022-01-03
  • 2021-11-28
  • 2021-10-23
  • 2021-12-24
相关资源
相似解决方案