如何动态加载部分布局 [英] how to loading part of layout dynamically

查看:106
本文介绍了如何动态加载部分布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有一个侧边栏,它的选项和菜单可能会有所不同,具体取决于登录的女巫.侧边栏应该是第一次在布局的div标签中加载,并保持不变,直到用户尚未注销.我怎样才能做到这一点?我的意思是我怎样才能第一次动态加载一个部分作为布局的一部分,然后再不接触它(使用RAZOR引擎)?
在此先感谢

i need to have a side bar that it`s options and menus could be differ depend on witch user is logged in. the side bar should load for the first time in the div tag of the layout and remain unchanged until the user has not logged out. how can i do that? i mean how can i dynamically load a section for the first time as a part of layout and do not touch it after that (using RAZOR engine)?
thanks in advance

推荐答案

您要查找的是@ Html.RenderAction(),它具有执行return PartialView();
的操作
在操作中,您可以测试用户/角色并确定要用什么填充模型,甚至确定要返回哪个视图.如果用户已登录,请创建相应的局部视图,以适当地呈现内容.

我还建议阅读 ASP .NET MVC最佳做法 [ ^ ],包括身份验证过滤器上的位.

干杯.
What you are looking for is @Html.RenderAction() with an action that does a return PartialView();

In the action, you can test for the user/role and determine what to populate the model with or even which view to return. Create corresponding partial views that render the content as appropriate, if the user is logged in.

I would also suggest reading through the ASP.NET MVC best practices[^] that Kazi Manzur has posted, including the bits on authentication filters.

Cheers.


嗨.感谢您的回答,但是当用户单击另一个链接并重定向到我的应用程序的另一个页面时会发生什么?答案是:
1)我的布局应重新呈现该部分并
2)将本节重新发送给客户,然后
3)侧边栏明显更改(侧边栏中的关闭标签和打开的标签将恢复为默认值)
这些是此解决方案的3个主要问题.我的目标是第一次加载此部分,此后此侧边栏将成为布局的一部分,不需要每次都渲染.你能给我另一个解决方案吗?
再次感谢.
hi. thanks to your answer but what happen when user click another link and redirected to another page of my application? the answer is:
1) my layout should re render that section and
2) resend the section to the client and
3) obviously side bar changed (closed tabs and opened tabs in sidebar will return to it`s default)
these are 3 major problem with this solution. my goal is to load this section for the first time and after that this sidebar going to be a part of the layout and does not need to render every time. can you give me another solution?
thanks again.


这篇关于如何动态加载部分布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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