如何动态添加/删除组件到MVC布局页面 [英] How to add/remove components dynamically to MVC layout page
本文介绍了如何动态添加/删除组件到MVC布局页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好;
我想在我的布局页面中添加一个div,仅用于特定视图。
请帮助!
谢谢
Hi all;
I want to add a div to my layout page for only specific view.
Please help!
Thanks
推荐答案
如何实现它,您可以在渲染该标记之前添加条件。例如
How you can achieve it, You can add condition before render that tag. For example
@{
if(ViewBag.ViewName == "test")
{
<div class="testcss">Good Morning!!!!!!!!!!!!!!!1</div>
}
}
如果ViewBag对象的ViewName属性从控制器设置为test然后你只渲染那个div块,否则它不会渲染。
If ViewName property of ViewBag object set to "test" from controller then you just render that div block otherwise it will not render.
谢谢SM Ahasan Habib先生你的回复。
实际上我使用了@section它工作得非常好。
@section 是调整共享视图的最佳方式。
Thank you Mr. S. M. Ahasan Habib for your reply.
Actually i used @section and it worked very well.
@section is the best way to adjust shared view.
这篇关于如何动态添加/删除组件到MVC布局页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文