zoukankan      html  css  js  c++  java
  • MVC调用部分视图PartialView

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Demo2017.Models
    {
        /* ~/Models/LoginModel.cs  */
        public class LoginModel
        {
            public string Name
            {
                get
                {
                    return "张星";
                }
            }
            public string Remark
            {
                get
                {
                    return "计算机系1班";
                }
            }
            public double Score
            {
                get
                {
                    return 99.12;
                }
            }
        }
    
        public class OtherModel
        {
            public string Name
            {
                get
                {
                    return "李琳琳";
                }
            }
            public string Remark
            {
                get
                {
                    return "旅游系1班";
                }
            }
            public double Score
            {
                get
                {
                    return 100;
                }
            }
        }  
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Demo2017.Models;
    
    namespace Demo2017.Controllers
    {
        /* ~/Controllers/HomeController.cs  */
        public class HomeController : Controller
        {
            // GET: /Home/  
            public ActionResult Index()
            {
                ViewData.Model = new LoginModel();
                return View();
            }
            public ActionResult GetPartialView3()
            {
                return PartialView("View3", new OtherModel());
            }
        }  
    }
    @using Demo2017.Models
    @model  LoginModel
    
    @{
        // ~/Views/Home/Index.cshtml
        ViewBag.Title = "Index";
    }
    @Scripts.Render("~/bundles/jquery")  
    <script type="text/javascript">
        $(function () {
            //Jquery调用PartialView
            $("#loadDiv").load("/Home/GetPartialView3");
        })
    </script>
    <hr />
    <h2>1.直接从LoginModel中获取数据的PartialView</h2>
    @Html.Partial("View1")
    <hr />
    <h2>2.从View中间接获取LoginModel数据的PartialView</h2>
    @Html.Partial("View2", Model.Score)
    <hr />
    <h2>3.使用Html.Action,通过Action获取OtherMode数据的PartialView</h2>
    <h2>@Html.Action("GetPartialView3")</h2>  
    
    <div id="loadDiv"></div>


    @using Demo2017.Models
    @* ~/Views/Shared/View1.cshtml *@
    @model LoginModel
    <h2>@Model.Name</h2>
    <h2>@Model.Remark</h2>
    <h2>@Model.Score</h2>

    @model System.Double
    @* ~/Views/Shared/View2.cshtml *@
    <h2>@Model</h2> 

    @model Demo2017.Models.OtherModel
    @* ~/Views/Shared/View3.cshtml *@
    <fieldset>
        <legend>OtherModel</legend>
    
        <div class="display-label">
            @Html.DisplayNameFor(model => Model.Name)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => Model.Name)
        </div>
    
        <div class="display-label">
            @Html.DisplayNameFor(model => Model.Remark)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => Model.Remark)
        </div>
    
        <div class="display-label">
            @Html.DisplayNameFor(model => Model.Score)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => Model.Score)
        </div>
    </fieldset>

  • 相关阅读:
    37 web自动化实战三 前置后置条件 (fixture yield知识点 conftest.py )
    36 web自动化实战二 pytest用例筛选 断言 生成测试报告 数据驱动
    35 web自动化 pytest框架详述
    性能测试jmeter 监控技术
    性能测试jmeter-接口实战2 函数助手 (随机生成手机号,压测手机号等数据库校验不能重复的接口)
    性能测试jmeter-接口实战1 项目中的关联
    性能测试值jmeter 的基本使用(关联 )
    34 selenium JS操作 文件上传 项目分析
    D. Road to Post Office 解析(思維)
    C. Bank Hacking 解析(思維)
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234079.html
Copyright © 2011-2022 走看看