参数传递到我的局部视图? [英] passing parameters to my partial view?

查看:96
本文介绍了参数传递到我的局部视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话给我这样的局部视图:

I am calling my partial view like this:

 <% Html.RenderPartial("~/controls/users.ascx"); %>

我可以传递参数给局部视图?我如何访问它们在实际users.ascx页面?

Can I pass parameters to partial view? How will I access them in the actual users.ascx page?

推荐答案

您可以传递模型对象的部分(比如字符串列表):

You could pass a model object to the partial (for example a list of strings):

<% Html.RenderPartial("~/controls/users.ascx", new string[] { "foo", "bar" }); %>

然后你强类型的局部和模式属性将是适当的类型:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Collections.Generic.IEnumerable<string>>" %>

<% foreach (var item in Model) { %>
    <div><%= Html.Encode(item) %></div>
<% } %>

这篇关于参数传递到我的局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆