用户控件和asp.net mvc

时间:2022-07-02 16:50:22

Here is one trivial question, that I am not sure how to handle. I need to display list of categories on every page, and to be able to choose items from a specific category to be displayed. I use asp.net MVC, and have chosen to create a user control that will display categories. My question is: what is the best approach to pass data to a user control. I already found some information in these blog posts:

有一个小问题,我不知道该怎么处理。我需要在每个页面上显示类别列表,并能够从特定类别中选择要显示的项。我使用asp.net MVC,并选择创建一个用户控件来显示类别。我的问题是:将数据传递给用户控件的最佳方法是什么?我已经在这些博文中找到了一些信息:

http://weblogs.asp.net/stephenwalther/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx

http://weblogs.asp.net/stephenwalther/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx

http://blog.matthidinger.com/2008/02/21/ASPNETMVCUserControlsStartToFinish.aspx

http://blog.matthidinger.com/2008/02/21/ASPNETMVCUserControlsStartToFinish.aspx

I would like also to hear your opinion.

我也想听听你的意见。

PS. I'd like to hear Jeff's opinion, especially because of his experience with UC's on *

我很想听听杰夫的意见,尤其是因为他在UC的*上的经历

2 个解决方案

#1


2  

I'm using mvc components, which replaced ascx user controls in preview 4.
Example: http://blog.wekeroad.com/blog/asp-net-mvc-preview-4-componentcontroller-is-now-renderaction/
So, you call components action from View, which then choose View to render. You can pass data in this call also.

我正在使用mvc组件,它在preview 4中取代了ascx用户控件。例如:http://blog.wead.com/blog/asp-netmvc -preview-4- componentcontrolleris -now-renderaction/因此,您可以从视图调用组件操作,然后选择视图呈现。您也可以在此调用中传递数据。

#2


1  

it is the mvc futures project. i will probably try this http://forums.asp.net/t/1303328.aspx. I need to render menu with categories.

这是mvc期货项目。我可能会尝试http://forums.asp.net/t/1303328.aspx。我需要渲染菜单的类别。

#1


2  

I'm using mvc components, which replaced ascx user controls in preview 4.
Example: http://blog.wekeroad.com/blog/asp-net-mvc-preview-4-componentcontroller-is-now-renderaction/
So, you call components action from View, which then choose View to render. You can pass data in this call also.

我正在使用mvc组件,它在preview 4中取代了ascx用户控件。例如:http://blog.wead.com/blog/asp-netmvc -preview-4- componentcontrolleris -now-renderaction/因此,您可以从视图调用组件操作,然后选择视图呈现。您也可以在此调用中传递数据。

#2


1  

it is the mvc futures project. i will probably try this http://forums.asp.net/t/1303328.aspx. I need to render menu with categories.

这是mvc期货项目。我可能会尝试http://forums.asp.net/t/1303328.aspx。我需要渲染菜单的类别。