MVC |分部视图 PartialView()

2021-07-04 06:03

阅读:606

YPE html>

标签:htm   name   server   each   inf   传参   mode   返回   四种   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApp.Controllers
{
using MvcApp.Models;
public class PartialViewDeomController : Controller
{
//
// 分部视图的作用一般用于嵌到如一些正常的视图中去。(类似与自定义控件)相当于: Server.Execute(string path)

public ActionResult PartialIndex()
{

var list = new List()
{
new T_UserInfo(){Id=1,UserName="无盐海",Name="凡斌"},
new T_UserInfo(){Id=1,UserName="阿宝",Name="周晶"},
};

//分部视图不会去执行_ViewStart.cshtml中的内容(分部视图以PartialView()返回)
return PartialView(list);
}
}
}

 

 

 

PartialIndex视图

@model List

 

Index视图与PartialIndex分部视图。(注意:这里是在Index视图里调用PartialIndex分部视图)

 

@{
Layout = null;
}
@using MvcApp.Models;




Index





@Html.Partial("PartialIndex", new List() { new T_UserInfo() { Id = 1, UserName = "无盐海", Name = "凡斌" }, new T_UserInfo() { Id = 1, UserName = "阿宝", Name = "周晶" }, })


@{
Html.RenderPartial("PartialIndex", new List() { new T_UserInfo() { Id = 1, UserName = "无盐海", Name = "凡斌" }, new T_UserInfo() { Id = 1, UserName = "阿宝", Name = "周晶" } });
}


@{Html.RenderAction("PartialIndex", "PartialViewDeom");}


@Html.Action("PartialIndex", new { controller = "PartialViewDeom" })



action

MVC |分部视图 PartialView()

标签:htm   name   server   each   inf   传参   mode   返回   四种   

原文地址:http://www.cnblogs.com/niejun/p/7121959.html


评论


亲,登录后才可以留言!