Python 官方文档:入门教程 => 点击学习
mvc3的分部视图相当于WEBfORM的用户控件1,新建一个控制器PartialController.cs2,新建一个视图(新建视图的时候,在弹出框中选择创建为分部视图)Message.cshtml,把这个文件放在Views/Shared这
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>
--结束END--
本文标题: MVC3----分部视图
本文链接: https://www.lsjlt.com/news/184766.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0