我打电话我的部分视图,像这样:
<% Html.RenderPartial("~/controls/users.ascx"); %>
我可以传递参数到部分视图吗?我将如何在实际的users.ascx页面中访问它们?
解决方法
您可以将模型对象传递给partial(例如字符串列表):
<% Html.RenderPartial("~/controls/users.ascx",new string[] { "foo","bar" }); %>
然后强烈键入partial,Model属性将是适当的类型:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Collections.Generic.IEnumerable<string>>" %> <% foreach (var item in Model) { %> <div><%= Html.Encode(item) %></div> <% } %>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。