<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET MVC</title><link>http://forums.asp.net/1146.aspx</link><description>Discussions regarding Model-View-Controller (MVC) support in ASP.NET.  &lt;a href="http://forums.asp.net/1215.aspx"&gt;T4MVC subforum&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2210249.aspx</link><pubDate>Tue, 04 Mar 2008 08:57:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2210249</guid><dc:creator>rjcox</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2210249.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2210249</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;rboarman:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/p&gt;&lt;p&gt;&lt;font face="Times New Roman" size="3"&gt;How do you all suggest we handle displaying certain controls for anonymous users and a different set for people who are logged in? What about for differing roles (admin vs. normal user)?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;I’d like to be able to mix and match a set of controls on a page that can decide when to display themselves based on the role of the user.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Thanks,&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Rick&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;You would be better off starting a new thread for a new question.Use the &amp;quot;write new post&amp;quot; button (the moderators are usually pretty quick to approve).&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2209455.aspx</link><pubDate>Mon, 03 Mar 2008 23:13:25 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2209455</guid><dc:creator>rboarman</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2209455.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2209455</wfw:commentRss><description>&lt;p&gt;&lt;font face="Times New Roman" size="3"&gt;How do you all suggest we handle displaying certain controls for anonymous users and a different set for people who are logged in? What about for differing roles (admin vs. normal user)?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;I’d like to be able to mix and match a set of controls on a page that can decide when to display themselves based on the role of the user.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Thanks,&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Rick&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2175068.aspx</link><pubDate>Fri, 15 Feb 2008 08:09:54 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2175068</guid><dc:creator>andhallberg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2175068.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2175068</wfw:commentRss><description>&lt;p&gt;Thanks for your reply. &lt;/p&gt;
&lt;p&gt;2. Yep, I was&amp;nbsp;wrong :-).&lt;/p&gt;
&lt;p&gt;3. Yes it&amp;nbsp;is the Controller for the Control, the Control&amp;#39;s controller - always a tounge twister when&amp;nbsp;trying to explain to someone :).&amp;nbsp;Without getting&amp;nbsp;too&amp;nbsp;MVC religious,&amp;nbsp;the core problem (as you&amp;nbsp;understand when you say we should only do R operations in this particular&amp;nbsp;&amp;quot;controller&amp;quot;) is that it is like a&amp;nbsp;controller&amp;#39;s ugly cousin or something. But hey,&amp;nbsp;it&amp;nbsp;works fine when you know what you are doing! I will definitely use this pattern sometime.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;/A&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2174278.aspx</link><pubDate>Thu, 14 Feb 2008 22:16:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2174278</guid><dc:creator>Pure Krome</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2174278.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2174278</wfw:commentRss><description>&lt;p&gt;tgmdbm - staying ontopic but slightly diverting ... can you please extend your previous example to include CACHING. So lets say .. for example .. we have the product list above .. but instead of getting the Linq to Sql to grab the data on every action request (ie. Page refresh :)&amp;nbsp; ) what about grabbing it from the asp.net cache bag? if this is a new thread by itself, then could you start a new topic, in these forums please.&lt;/p&gt;&lt;p&gt;It&amp;#39;s exciting that we&amp;#39;re all quickly nutting out some of these MVC questions. :)&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2173871.aspx</link><pubDate>Thu, 14 Feb 2008 18:49:05 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2173871</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2173871.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2173871</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;andhallberg:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;1.&amp;nbsp;Some digging is necessary to realize
that&amp;nbsp;&amp;lt;% Html.RenderAction... %&amp;gt;&amp;nbsp;renders the &amp;quot;Widget&amp;quot;
ProductList.ascx&lt;/div&gt;&lt;/BLOCKQUOTE&gt; &lt;/p&gt;
&lt;p&gt;Agreed, there is a level of separation that could lead to some confusion/frustration, but
if you find a good naming convention for &amp;quot;Control Controllers&amp;quot; and
their respective Controls it should ease the pain.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;andhallberg:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;2. ViewData[&amp;quot;productsList&amp;quot;] is fragile, we have to make sure that all pages that use the widget do not overwrite this value.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;Not at all. What i think you&amp;#39;ve overlooked here is that the ProductList Control renders in its own context, separate from the page. If the initial (page) controller uses the &amp;quot;productsList&amp;quot; variable in the &amp;quot;weak typed&amp;quot; ViewData this will NOT be overwritten by the ProductListController!!! &lt;/p&gt;&lt;p&gt;Ideally, however, you would use the strongly typed version, but in either case, the two controllers do not interact!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;andhallberg:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;3. &amp;quot;ProductListController&amp;quot; is a controller for the
model...&amp;quot;ProductList&amp;quot;?&amp;nbsp;As pointed out earlier, it is not a Controller
-&amp;nbsp;Model couple in the traditional sense that the Model is a domain
object.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;just a correction here: &amp;quot;ProductListController&amp;quot; is a controller for the &lt;b&gt;Control&lt;/b&gt; &amp;quot;ProductList&amp;quot;.I would even say that ProductListController shouldn&amp;#39;t &amp;quot;control&amp;quot; Products (i.e. it should only do the R from CRUD). You&amp;#39;ll typically already have a ProductController to do all that. Although, from a plug&amp;#39;n&amp;#39;play/reusability point of view you&amp;#39;ll probably want to implement CRUD. Its up to you.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The _biggest_ problem i see with this, is that we have an overload for the term &amp;quot;control&amp;quot;, and so just talking about it is a point of confusion. I hope i&amp;#39;ve made myself clear by using &amp;quot;Control&amp;quot; for the noun and &amp;quot;control&amp;quot; for the verb.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2173016.aspx</link><pubDate>Thu, 14 Feb 2008 13:10:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2173016</guid><dc:creator>pure.krome</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2173016.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2173016</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;andhallberg:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
&lt;p&gt;2. ViewData[&amp;quot;productsList&amp;quot;] is fragile, we have to make sure that all pages that use the widget do not overwrite this value.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;you could get around this by adding a public const string to the MVC View User Control? This might help it remain unique if you make the value on this string pretty unique :) maybe?&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172811.aspx</link><pubDate>Thu, 14 Feb 2008 11:20:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172811</guid><dc:creator>andhallberg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172811.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172811</wfw:commentRss><description>&lt;p&gt;tgmdbm, nice solution. My only concerns are&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp;Some digging is necessary to realize that&amp;nbsp;&amp;lt;% Html.RenderAction... %&amp;gt;&amp;nbsp;renders the &amp;quot;Widget&amp;quot; ProductList.ascx.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. ViewData[&amp;quot;productsList&amp;quot;] is fragile, we have to make sure that all pages that use the widget do not overwrite this value.&lt;/p&gt;
&lt;p&gt;3. &amp;quot;ProductListController&amp;quot; is a controller for the model...&amp;quot;ProductList&amp;quot;?&amp;nbsp;As pointed out earlier, it is not a Controller -&amp;nbsp;Model couple in the traditional sense that the Model is a domain object.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Other than that it&amp;nbsp;is a nice solution to the &amp;quot;I need to bundle view + logic into reusable unit&amp;quot; problem&amp;nbsp;that one might encounter sometimes. Great work.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172625.aspx</link><pubDate>Thu, 14 Feb 2008 09:16:07 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172625</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172625.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172625</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;sliderhouserules:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;There is some elegance and simplicity to this, but you don&amp;#39;t think the above is clearly tying the view to the controller, which is all the bad that you&amp;#39;re decrying about tying the view to the Model? How is strongly typing (generic form) a View page not tying it to the Model, anyway?&lt;/div&gt;&lt;/BLOCKQUOTE&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;In this case you are tying the view to a controller, but the point is it&amp;#39;s the controller for a Control, so I don&amp;#39;t see that as any different from using a regular Control. Also there should be an overload of this which simply takes the name of the controller and action, which obviously isn&amp;#39;t tied to anything.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;As for the View being tied to the Model, that&amp;#39;s not the case at all. The View is tied to the data which the Controller gives it. It&amp;#39;s perfectly viable to create restrictions of the model classes to pass to the view. something akin to &lt;b&gt;ViewProduct x = new ViewProduct(product). &lt;/b&gt;This could contain less fields than the model class and then you&amp;#39;ve created a very clear separation. The fact is that it&amp;#39;s usually appropriate for the View to have access to most of the fields of the Model classes and so creating these intermediary classes are a seen as a waste of time.&lt;/p&gt;&lt;p&gt;The emphasis however is on &lt;b&gt;not calling ANY methods on ANY of the Model classes from within the View!&lt;/b&gt; Only accessing properties!&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;As for an implementation of the RenderAction helper method, you can just take my &lt;b&gt;Call&lt;/b&gt; code from earlier and change its name. It works fine for me, let me know if yo find a bug in it.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Good luck&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172504.aspx</link><pubDate>Thu, 14 Feb 2008 08:03:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172504</guid><dc:creator>sliderhouserules</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172504.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172504</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;pure.krome:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
&lt;p&gt;hmm. this might sound really noobish .. but where is the RenderAction code? i can&amp;#39;t find it anywhere (well, any official comment / code).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;just when i thought i was there!&lt;/p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;It hasn&amp;#39;t been released yet. It&amp;#39;ll be in the next Toolkit release, he said.</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172500.aspx</link><pubDate>Thu, 14 Feb 2008 08:02:43 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172500</guid><dc:creator>sliderhouserules</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172500.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172500</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;tgmdbm:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
&lt;p&gt;&lt;b&gt;Views&lt;br /&gt;+-- Home&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +-- Index.aspx&lt;/b&gt; &lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="dir"&gt;&amp;lt;% &lt;/span&gt;Html.RenderAction&amp;lt;ProductListController&amp;gt;( c =&amp;gt; c.Show() ) &lt;span class="dir"&gt;%&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;There is some elegance and simplicity to this, but you don&amp;#39;t think the above is clearly tying the view to the controller, which is all the bad that you&amp;#39;re decrying about tying the view to the Model? How is strongly typing (generic form) a View page not tying it to the Model, anyway?&lt;/pre&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172332.aspx</link><pubDate>Thu, 14 Feb 2008 06:18:14 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172332</guid><dc:creator>pure.krome</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172332.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172332</wfw:commentRss><description>&lt;p&gt;hmm. this might sound really noobish .. but where is the RenderAction code? i can&amp;#39;t find it anywhere (well, any official comment / code).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;just when i thought i was there!&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172210.aspx</link><pubDate>Thu, 14 Feb 2008 04:49:25 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172210</guid><dc:creator>pure.krome</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172210.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172210</wfw:commentRss><description>&lt;p&gt;DOL (drool out loud)!! this is so kewl. brb! Thanks heaps &lt;strong&gt;tgmdbm.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="txtIrcMe"&gt;&amp;nbsp;*&amp;nbsp;pure.krome runs off to refactor my lame code.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172178.aspx</link><pubDate>Thu, 14 Feb 2008 04:21:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172178</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172178.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172178</wfw:commentRss><description>&lt;p&gt;You can do it like that but you&amp;#39;re breaking encapsulation.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;pure.krome:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;+\Controllers\HomeController.cs&amp;nbsp; &amp;lt;-- Index method calls the static PrepareViewData(..) method.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;I have a real problem with this, you are tying the Controller to the View (by calling that static method) and you shouldn&amp;#39;t do that. You&amp;#39;re also tying the View to the Model and that&amp;#39;s a HUGE no no (I&amp;#39;m assuming the static method, PrepareViewData, is calling to the Model to get the list of products??).&lt;/p&gt;

&lt;p&gt;As you&amp;#39;ve already pointed out this is not very DRY. You need to do the same thing for every ViewPage which contains this control.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;In my example above you can bundle up the WidgetController and the Widget and pass that to anyone to reuse. I&amp;#39;ll rewrite the example to better suit your naming, and since Rob has created the RenderAction method i&amp;#39;ll use that.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Controllers&lt;br /&gt;+-- HomeController.cs&lt;/b&gt;&lt;/p&gt;

&lt;pre class="coloredcode"&gt;[ControllerAction]&lt;br /&gt;&lt;span class="kwd"&gt;public void&lt;/span&gt; Index() { RenderView( &lt;span class="st"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt; ); } &lt;span class="cmt"&gt;// note we don&amp;#39;t have to get any products here.&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;&lt;b&gt;Views&lt;br /&gt;+-- Home&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +-- Index.aspx&lt;/b&gt; &lt;/p&gt;

&lt;pre class="coloredcode"&gt;&lt;span class="dir"&gt;&amp;lt;% &lt;/span&gt;Html.RenderAction&amp;lt;ProductListController&amp;gt;( c =&amp;gt; c.Show() ) &lt;span class="dir"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;b&gt;Controllers&lt;br /&gt;+-- Controls&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +-- ProductListController.cs &lt;/b&gt;&lt;br /&gt;&lt;/p&gt;

&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;public class&lt;/span&gt; ProductListController : Controller&lt;br /&gt;{&lt;br /&gt;  [ControllerAction]&lt;br /&gt;  &lt;span class="kwd"&gt;public void&lt;/span&gt; Show() &lt;span class="cmt"&gt;// this gets called by Html.RenderAction&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  {&lt;br /&gt;    ViewData[&lt;span class="st"&gt;&amp;quot;productsList&amp;quot;&lt;/span&gt;] = db.Products; &lt;span class="cmt"&gt;// get data from somewhere&lt;/span&gt;&lt;br /&gt;    RenderView( &lt;span class="st"&gt;&amp;quot;ProductList&amp;quot;&lt;/span&gt; );&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;&lt;b&gt;Views&lt;br /&gt;+-- ProductList&lt;/b&gt; (or Shared)&lt;br /&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +-- ProductList.ascx&lt;/b&gt;&lt;/p&gt;
&lt;span class="kwd"&gt;&lt;/span&gt;
&lt;pre class="coloredcode"&gt;&lt;pre class="coloredcode"&gt;&amp;lt;&lt;span class="tag"&gt;ul&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;span class="dir"&gt;&amp;lt;% &lt;/span&gt;foreach(Product p in ViewData[&amp;quot;productsList&amp;quot;]) { &lt;span class="dir"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;  &amp;lt;&lt;span class="tag"&gt;li&lt;/span&gt;&amp;gt;&lt;span class="dir"&gt;&amp;lt;%=&lt;/span&gt; p.Name &lt;span class="dir"&gt;%&amp;gt;&lt;/span&gt;&amp;lt;/&lt;span class="tag"&gt;li&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;span class="dir"&gt;&amp;lt;% &lt;/span&gt;} &lt;span class="dir"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;/&lt;span class="tag"&gt;ul&lt;/span&gt;&amp;gt;&amp;nbsp;&lt;br /&gt;&lt;/pre&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;As you can see all we have to do is call Html.RenderAction from within any view which wants a ProductList and hey presto. The logic is encapsulated in the ProductListController and we have very clear separation of concerns. And no need for any codebehind.&lt;br /&gt; &lt;/p&gt;&lt;p&gt;A beautiful solution.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2172129.aspx</link><pubDate>Thu, 14 Feb 2008 03:49:16 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2172129</guid><dc:creator>pure.krome</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2172129.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2172129</wfw:commentRss><description>&lt;p&gt;Yeah - i&amp;#39;ve had a bit more luck with MVC View Web Controls. Firstly, i need to thank BEN SCHEIRMAN for helping me out, here. he really got the ball rolling.&lt;/p&gt;
&lt;p&gt;What i ended up doing (and it was really getting my head around what an MVC&amp;nbsp;&amp;nbsp;View User Control&amp;nbsp;_really_ is, compared to my previous incorrect understanding that a VUC has some logic associated with it) was the following.&lt;/p&gt;
&lt;p&gt;Index method/action in the HomeController:- That sets up _all_ the ViewData, for both the html stuff on the Index.aspx &amp;#39;view&amp;#39; and for the ProductsList VUC that exists in that view. Now, because the default Index action is being called on the HomeController, all the correct view data stuff for itself AND it&amp;#39;s children (ie. the index view knows that it has some children view user controls) are being setup there. When it came to rending the specific data on that ProductList VUC (remember, the index view asks to RenderUserControl(..)), the viewdata already exists in that child view user control being rendered.&lt;/p&gt;
&lt;p&gt;as such, no vuc controller stuff was ever need.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure if this is the right method, though .. but this was what i sorted figured out on the weekend and this week during work i&amp;#39;ve been spending all my time getting this in action.&lt;/p&gt;
&lt;p&gt;I used to think the View User Control as a completly seperate reusable component .. where u could box it up into a dll or something and give it to whoever -- just like any commerical webform component out there. It&amp;#39;s not. The _VIEW_ is completly reusable, but not the&amp;nbsp;logic. The logic - which in this case is getting a list of products and then adding that to the ViewData&amp;nbsp;- needs to be handled on every view where this reusable view user control exists.&lt;/p&gt;
&lt;p&gt;That said, i&amp;#39;ve put the static method that impliments this logic to the code behind of the view user control .. so the logic is in one place. the controllers (ie. the Index &amp;#39;action&amp;#39; in the HomeController) all call this one method and bobs your uncle.&lt;/p&gt;
&lt;p&gt;i&amp;#39;ll try and draw a map of what the code looks like.&lt;/p&gt;
&lt;p&gt;+Views\Home\Index.aspx&amp;nbsp;&amp;nbsp; &amp;lt;-- The main page view. This has a single View User Control inside this view, called ProductList.ascx.&lt;br /&gt;+\Views\Shared\ProductList.ascx&amp;nbsp;&amp;nbsp; &amp;lt;-- reusable view user control. This displays a unordered list of products.&lt;br /&gt;+\Views\Shared\ProductList.ascx.cs&amp;nbsp; &amp;lt;--- static method :: public static void PrepareViewData( ... the objects that the view user control requires) { .. }&lt;br /&gt;+\Controllers\HomeController.cs&amp;nbsp; &amp;lt;-- Index method calls the static PrepareViewData(..) method.&lt;/p&gt;
&lt;p&gt;done. Does that sound like i&amp;#39;m close?&lt;/p&gt;</description></item><item><title>Re: Web User Controls + Controllers?</title><link>http://forums.asp.net/thread/2171910.aspx</link><pubDate>Thu, 14 Feb 2008 00:02:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2171910</guid><dc:creator>tgmdbm</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2171910.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2171910</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;pure.krome, did you get anywhere with this?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>