添加一个PartialController控制器

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.Mvc;

 namespace MvcValidateDemo.Controllers
 {
     public class PartialController : Controller
     {
         //
         // GET: /Partial/

         public ActionResult Index()
         {
             return View();
         }

         public ActionResult About()
         {

             ViewData["key"] = "Action  执行了";
             ViewBag.Demo = "Action Bag执行了";
             return View();
         }

     }
 }

添加About视图

 @{
     Layout = null;
 }

 <!DOCTYPE html>

 <html>
 <head>
     <meta name="viewport" content="width=device-width" />
     <title>About</title>
 </head>
 <body>
     <div>
         About :@ViewBag.Demo+@ViewData["key"]
     </div>
 </body>
 </html>

添加Index视图

 @{
     Layout = null;
 }

 <!DOCTYPE html>

 <html>
 <head>
     <meta name="viewport" content="width=device-width" />
     <title>Index</title>
 </head>
 <body>
     <div>
         @{
             Html.RenderPartial("About");//把子视图渲染到当前位置

             Html.RenderAction("About");//把Action的结果渲染到当前的位置
         }
     </div>
 </body>
 </html>
04-26 14:50
查看更多