<?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: Ambiguous controllers</title><link>http://forums.asp.net/thread/2628794.aspx</link><pubDate>Thu, 18 Sep 2008 05:09:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2628794</guid><dc:creator>wenhx</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2628794.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2628794</wfw:commentRss><description>&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Ambiguous controllers</title><link>http://forums.asp.net/thread/2061856.aspx</link><pubDate>Sat, 15 Dec 2007 20:43:07 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2061856</guid><dc:creator>abombss</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2061856.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2061856</wfw:commentRss><description>&lt;p&gt;Thanks Sean... I meant to say a RouteHandler but wrote about a ControllerFactory... &lt;img src="http://forums.asp.net/emoticons/emotion-1.gif" alt="Smile" /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Ambiguous controllers</title><link>http://forums.asp.net/thread/2061202.aspx</link><pubDate>Sat, 15 Dec 2007 02:15:38 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2061202</guid><dc:creator>slynch</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2061202.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2061202</wfw:commentRss><description>&lt;p&gt;The following should work till they have the GetControllerType of the MvcHandler class take namespaces into account, at which time I suggest you forget these use theirs.&amp;nbsp; &lt;pre class="coloredcode"&gt;	
&lt;span class="kwd"&gt;public class&lt;/span&gt; MvcRouteHandlerNS : MvcRouteHandler
	{
		&lt;span class="kwd"&gt;protected override&lt;/span&gt; IHttpHandler GetHttpHandler(RequestContext requestContext)
		{
			&lt;span class="kwd"&gt;return new&lt;/span&gt; MvcHandlerNS()
			{
				RequestContext = requestContext
			};
		}
	}
	&lt;span class="kwd"&gt;public class&lt;/span&gt; MvcHandlerNS: MvcHandler
	{
		&lt;span class="kwd"&gt;protected static object&lt;/span&gt; _customLock = &lt;span class="kwd"&gt;new object&lt;/span&gt;();
		&lt;span class="kwd"&gt;protected static&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwd"&gt;string&lt;/span&gt;, Type&amp;gt; _typeCache = &lt;span class="kwd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwd"&gt;string&lt;/span&gt;, Type&amp;gt;();

		&lt;span class="kwd"&gt;protected override&lt;/span&gt; Type GetControllerType(&lt;span class="kwd"&gt;string&lt;/span&gt; controller)
		{
			IDictionary&amp;lt;&lt;span class="kwd"&gt;string&lt;/span&gt;,&lt;span class="kwd"&gt;object&lt;/span&gt;&amp;gt; routeDefaults = &lt;span class="kwd"&gt;this&lt;/span&gt;.RequestContext.RouteData.Values;
			&lt;span class="kwd"&gt;if&lt;/span&gt; (routeDefaults.Keys.Contains(&lt;span class="st"&gt;&amp;quot;ns&amp;quot;&lt;/span&gt;))
			{
				&lt;span class="kwd"&gt;string&lt;/span&gt; typeName = String.Format(&lt;span class="st"&gt;&amp;quot;{0}.{1}Controller&amp;quot;&lt;/span&gt;, routeDefaults[&lt;span class="st"&gt;&amp;quot;ns&amp;quot;&lt;/span&gt;], controller);
				Type controllerType = &lt;span class="kwd"&gt;null&lt;/span&gt;;
				&lt;span class="kwd"&gt;lock&lt;/span&gt; (_customLock)
				{
					&lt;span class="kwd"&gt;if&lt;/span&gt; (_typeCache.ContainsKey(typeName))
						&lt;span class="kwd"&gt;controllerType =&lt;/span&gt; _typeCache[typeName];

&lt;/pre&gt;&lt;pre class="coloredcode"&gt;					if(controllerType == null)&lt;br /&gt;					{&lt;br /&gt;						controllerType = Type.GetType(typeName);
						&lt;span class="kwd"&gt;if&lt;/span&gt; (controllerType!=&lt;span class="kwd"&gt;null&lt;/span&gt;)
						{
							_typeCache.Add(typeName, controllerType);
						}					&lt;br /&gt;					}&lt;br /&gt;
				}&lt;br /&gt;				if(controllerType!=null)&lt;br /&gt;					return controllerType;
			}
			&lt;span class="kwd"&gt;return base&lt;/span&gt;.GetControllerType(controller);			
		}
	}
&lt;/pre&gt;&amp;nbsp;And in the glabal.asax class use &lt;pre class="coloredcode"&gt;RouteTable.Routes.Add(&lt;span class="kwd"&gt;new&lt;/span&gt; Route
{
	Url = &lt;span class="st"&gt;&amp;quot;SomeDirectory/[action]/[id]&amp;quot;&lt;/span&gt;,//Base path needs to be specified
	Defaults = &lt;span class="kwd"&gt;new&lt;/span&gt; { controller = &lt;span class="st"&gt;&amp;quot;Bar&amp;quot;&lt;/span&gt;, ns = &lt;span class="st"&gt;&amp;quot;Company.MySite.Controllers.Foo&amp;quot;&lt;/span&gt;, action = &lt;span class="st"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;, id = (&lt;span class="kwd"&gt;string&lt;/span&gt;)&lt;span class="kwd"&gt;null&lt;/span&gt; },
	RouteHandler = &lt;span class="kwd"&gt;typeof&lt;/span&gt;(MvcRouteHandlerNS)
});
&lt;/pre&gt;
&lt;p&gt;Though personally, I would just name my somedirectory/foobarcontroller SomeDirectoryFooBarController and SomeOtherDirectoryFooBarController, and forget I ever saw this code. At least until they add support for namespaces in the controllers. &lt;/p&gt;
&lt;p&gt;Edit: Especially since it looks like they are looking into it already.&lt;/p&gt;</description></item><item><title>Re: Ambiguous controllers</title><link>http://forums.asp.net/thread/2061193.aspx</link><pubDate>Sat, 15 Dec 2007 01:59:21 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2061193</guid><dc:creator>Haacked</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2061193.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2061193</wfw:commentRss><description>&lt;p&gt;This is definitely a problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We&amp;#39;re planning to address this with the ability to disambiguation of controller selection by allowing you to specify namespaces.&lt;/p&gt;</description></item><item><title>Re: Ambiguous controllers</title><link>http://forums.asp.net/thread/2061157.aspx</link><pubDate>Sat, 15 Dec 2007 00:31:52 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2061157</guid><dc:creator>abombss</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2061157.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2061157</wfw:commentRss><description>&lt;p&gt;For now you need a custom controller factory.&lt;/p&gt;&lt;p&gt;The &lt;a href="http://www.codeplex.com/MVCContrib"&gt;MVCContrib &lt;/a&gt;project has some examples of how to build one.&amp;nbsp;&lt;/p&gt;&lt;p&gt;It would be great if we could get support for partitioning areas of an application with namespaces or something like the monorail &amp;quot;Area&amp;quot; parameter on the ControllerDetailsAttribute&amp;nbsp;&lt;/p&gt;&lt;p&gt;Adam&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Ambiguous controllers</title><link>http://forums.asp.net/thread/2060951.aspx</link><pubDate>Fri, 14 Dec 2007 21:12:01 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2060951</guid><dc:creator>RRidge</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2060951.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=2060951</wfw:commentRss><description>&lt;p&gt;I&amp;#39;ve been playing with nesting views and controllers in subdirectories for more fine grained partitioning, I&amp;#39;ve discovered through reflector I can do a RenderView(&amp;quot;~/Views/SomeDirectory/SomeOtherDirectory/File.aspx&amp;quot;) and it overrides your default search in Views and then in Views/Shared.&amp;nbsp; I am pleased.&lt;/p&gt;&lt;p&gt;However, I am having some difficulty with controllers.&amp;nbsp; I see that you&amp;#39;re expecting Foo followed by Controller (such as FooController), but your search is through the entire assembly, such that if I have Controllers/FooController and Controllers/SomeDirectory/FooController it sees two FooControllers and throws an ambiguous controller invalid operation exception.&amp;nbsp; The exception&amp;#39;s suggested action is to disambiguate the controllers by using the full namespace in the route.&amp;nbsp; When I attempt to set a route with a fully qualified controller default property, I end up getting an invalid operation exception suggesting that the controller cannot be found, for example controller = &amp;quot;Company.MySite.Controllers.Foo.BarController&amp;quot;, when that is indeed the correct fully qualified type name.&amp;nbsp; Apparently I&amp;#39;m missing something important here, but I&amp;#39;m not sure what.&lt;/p&gt;&lt;p&gt;I like the story for dealing with nesting views and being able to supply a virtual path, but it seems like something is missing for dealing with nested controllers in subdirectories...&amp;nbsp; I&amp;#39;m not entirely clear on what I want here, but I do know that having an explosion of classes directly under Controllers and Views seems like it would lead to some management issues with a sizable site...&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>