码迷,mamicode.com
首页 > Web开发 > 详细

Html.RenderPartial和Html.RenderAction的区别

时间:2015-12-09 11:38:50      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

添加一个PartialController控制器

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 
 7 namespace MvcValidateDemo.Controllers
 8 {
 9     public class PartialController : Controller
10     {
11         //
12         // GET: /Partial/
13 
14         public ActionResult Index()
15         {
16             return View();
17         }
18 
19         public ActionResult About()
20         {
21 
22             ViewData["key"] = "Action  执行了";
23             ViewBag.Demo = "Action Bag执行了";
24             return View();
25         }
26 
27     }
28 }

添加About视图

 1 @{
 2     Layout = null;
 3 }
 4 
 5 <!DOCTYPE html>
 6 
 7 <html>
 8 <head>
 9     <meta name="viewport" content="width=device-width" />
10     <title>About</title>
11 </head>
12 <body>
13     <div>
14         About :@ViewBag.Demo+@ViewData["key"]
15     </div>
16 </body>
17 </html>

添加Index视图

 1 @{
 2     Layout = null;
 3 }
 4 
 5 <!DOCTYPE html>
 6 
 7 <html>
 8 <head>
 9     <meta name="viewport" content="width=device-width" />
10     <title>Index</title>
11 </head>
12 <body>
13     <div>
14         @{
15             Html.RenderPartial("About");//把子视图渲染到当前位置
16 
17             Html.RenderAction("About");//把Action的结果渲染到当前的位置
18         }
19     </div>
20 </body>
21 </html>

 

Html.RenderPartial和Html.RenderAction的区别

标签:

原文地址:http://www.cnblogs.com/mylovemygirl/p/5031941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!