zoukankan      html  css  js  c++  java
  • Html.RenderPartial和Html.RenderAction的区别

    添加一个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>
  • 相关阅读:
    nuget
    C#枚举中使用Flags特性
    情感分析
    docker
    core部署
    脱壳系列_2_IAT加密壳_详细分析(含脚本)
    安全公司-* * * *-面试题:_ 安卓逆向分析分享
    18_ShadowWalker
    17_页面异常接管
    16_TLB与流水线
  • 原文地址:https://www.cnblogs.com/qinsilandiao/p/5031941.html
Copyright © 2011-2022 走看看