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>
  • 相关阅读:
    filter函数和map函数
    生成器面试题
    装饰器激活生成器
    移动平均値
    send()方法的初识
    监听文件的输入
    迭代器抛出异常处理方法
    装饰器-wraps
    多个装饰器装饰一个函数
    WebView 安卓原生java与h5,js交互
  • 原文地址:https://www.cnblogs.com/qinsilandiao/p/5031941.html
Copyright © 2011-2022 走看看