ASP.NET MVC dynamically load user control, like in ASP.NET Web Forms

点点圈 提交于 2019-12-08 13:34:55

问题


Hallo, my team and I are about to start a project, and we would really like to use ASP.NET MVC, not the Web Forms. Why? Nothing special, just we want to learn it well and to measure what would be better to use in future projects.

But, our project has important request. We need ability to dynamically load user controls, that can be created and uploaded in runtime. With ASP.NET Web Forms and it's LoadControl method it's simple.

Can we do something like that with MVC?

Tnx


回答1:


Partial views are what you want.

MVC - Dynamically loading Partial Views




回答2:


partial views will do the trick.. or you might want to rethink why you are using a user control. is this a third party control? could this be rewritten?




回答3:


You can use

<%

foreach (var thing in things)

    Html.RenderPartial("location/page.ascx",thing);

%>

from within your view



来源:https://stackoverflow.com/questions/1367829/asp-net-mvc-dynamically-load-user-control-like-in-asp-net-web-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!