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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

smartsmile2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值