当用户具有特定角色时,我有一些应该呈现的部分视图。
现在,我想避免做类似的事情
<% if(user is in role){..here goes the html.. }%>
Run Code Online (Sandbox Code Playgroud)
我希望能够做到(在 ascx 的顶部):
<% this.RenderOnlyForRoles(list of roles) %>
Run Code Online (Sandbox Code Playgroud)
现在,在 BasePartialView 中,我有一个在调用 RenderOnlyForRoles 时填充的角色列表。
问题是 RenderOnlyForRoles 在我能想到的所有事件之后被调用:)并且我无法停止控件的渲染。
关于如何获得我想要的东西有什么想法吗?
编辑:有人知道其他视图引擎是否支持这个?
public static void RenderOnlyForRoles(this HtmlHelper html, List<string> roles))
{
if (check if user in roles)
{
html.RenderPartial(yourview);
}
}
Run Code Online (Sandbox Code Playgroud)
善良,
担
| 归档时间: |
|
| 查看次数: |
2709 次 |
| 最近记录: |