如何在页面和用户控件之间传递数据
1个回答
展开全部
默认情况下,PartialView能够访问到View里面的 ViewData.
如果页面在RenderPartial的时候,希望特别地传递数据,则按照下面的方法
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Web.Models.GalleryListItem>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
相册
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
Html.RenderPartial("Gallery", ViewData["my"], new ViewDataDictionary() { { "Title", "我的相册" } });
%>
<%
Html.RenderPartial("Gallery", ViewData["public"], new ViewDataDictionary() { { "Title", "公开的相册" } });
%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server">
</asp:Content>
如果页面在RenderPartial的时候,希望特别地传递数据,则按照下面的方法
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Web.Models.GalleryListItem>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
相册
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
Html.RenderPartial("Gallery", ViewData["my"], new ViewDataDictionary() { { "Title", "我的相册" } });
%>
<%
Html.RenderPartial("Gallery", ViewData["public"], new ViewDataDictionary() { { "Title", "公开的相册" } });
%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server">
</asp:Content>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询