发布时间:2019-08-05 16:35:13编辑:auto阅读(1963)
MVC3的分部视图相当于webform的用户控件
1,新建一个控制器PartialController.cs
2,新建一个视图(新建视图的时候,在弹出框中选择创建为分部视图)Message.cshtml,把这个文件放在Views/Shared这个文件夹下(约定优先于配置)
3,在视图中引用(Store/Index.cshtml)
-----控制器(PartialController.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MusicStore.Controllers
{
    public class PartialController : Controller
    {
        //
        // GET: /Partial/
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Message()
        {
            return PartialView();//返回分部视图
        }
    }
}-----分部视图(Message.cshtml)
我是分部视图
-----视图(Index.cshtml)
@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
<!--引用分部视图(输出:我是分部视图)-->
<li>@Html.Partial("Message")</li>
<!--Ajax请求模式(输出:我是分部视图)-->
<li id="a"></li>
<script type="text/javascript">
    $(function () {
        $("#a").load('/Partial/Message');
    });
</script>
上一篇: 3.btrfs管理及应用
下一篇: MPLS的简单配置3
 51197
 50617
 41239
 38055
 32517
 29424
 28285
 23143
 23098
 21436
 1493°
 2206°
 1831°
 1761°
 2068°
 1818°
 2503°
 4200°
 4064°
 2904°