Problem with route in VS2011 Beta http://forums.asp.net/t/1796863.aspx/1?Problem+with+route+in+VS2011+Beta+Wed, 02 May 2012 07:34:36 -040017968634951018http://forums.asp.net/p/1796863/4951018.aspx/1?Problem+with+route+in+VS2011+Beta+Problem with route in VS2011 Beta <p>Hi</p> <p>Can anyone see where i'm going wrong here, as i'm not sure what i need to add to the form.&nbsp;My form displays</p> <pre id="line1"><span>&lt;<span class="start-tag">form</span> <span class="attribute-name">action</span>=&quot;<a class="attribute-value" href="">/Home</a>&quot; <span class="attribute-name">id</span>=&quot;<a class="attribute-value">frmSearch</a>&quot; <span class="attribute-name">method</span>=&quot;<a class="attribute-value">get</a>&quot;&gt; it should point to /Search/Index</span></pre> <p>I'm using VS2011 Beta</p> <p>Thanks</p> <p>George</p> <pre><span>I'm using </span>Html.BeginRouteForm and the route is named SearchResults</pre> <pre class="prettyprint">routes.MapRoute( name: &quot;SearchResults&quot;, url: &quot;{controller}/{action}/{id}&quot;, defaults: new { controller = &quot;Search&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional } ); @using(Html.BeginRouteForm(&quot;SearchResults&quot;,FormMethod.Get, new {@id = &quot;frmSearch&quot;})) { Html.RenderPartial(&quot;~/Views/Home/_pvDisplaySearch.cshtml&quot;); }</pre> <pre></pre> <pre><span><span style="font-family: Consolas; font-size: small;" size="2" face="Consolas"><span style="font-family: Consolas; font-size: small;" size="2" face="Consolas"></span></span></span></pre> 2012-04-25T13:59:47-04:004951059http://forums.asp.net/p/1796863/4951059.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>I think I have seen what your problem is.&nbsp; In your Route, you are defining an optional constructor.&nbsp;</p> <pre class="prettyprint">routes.MapRoute( name: &quot;SearchResults&quot;, url: &quot;{controller}/{action}/{id}&quot;, defaults: new { controller = &quot;Search&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional } );</pre> <p>You need to change this to the following:</p> <pre class="prettyprint">routes.MapRoute( name: "SearchResults", url: "Search/Index/{id}", new { controller = "Home", action = "Create" }, new { httpMethod = new HttpMethodConstraint("GET") } ); </pre> 2012-04-25T14:17:17-04:004951139http://forums.asp.net/p/1796863/4951139.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Hi Neil</p> <p>Thanks, that works but the url is not in the format i'm looking for.</p> <p>This is how it displays: <a href="http://localhost:49514/Search/Index?q=test&amp;b=Web&amp;o=Web&amp;p=1"> http://localhost:49514/Search/Index?q=test&amp;b=Web&amp;o=Web&amp;p=1</a></p> <p>What i'm looking for is <a href="http://www.mydomain.com/SearchResults/test/SearchOption/Web/Page/1"> http://www.mydomain.com/SearchResults/test/SearchOption/Web/Page/1</a></p> <p>Where SearchOption: o=web</p> <p>Thanks</p> <p>George</p> <p>&nbsp;</p> 2012-04-25T14:58:41-04:004951145http://forums.asp.net/p/1796863/4951145.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Change the&nbsp;URL within the route.&nbsp; Currently the route is set for /Search/Index/{id}.&nbsp; Change this to your required URL.</p> 2012-04-25T15:00:38-04:004951179http://forums.asp.net/p/1796863/4951179.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Hi Neil</p> <p>Tried that but form is: <span>&lt;<span class="start-tag">form</span> <span class="attribute-name"> action</span>=&quot;<a class="attribute-value" href=""></a>&quot; <span class="attribute-name"> id</span>=&quot;<a class="attribute-value">frmSearch</a>&quot; <span class="attribute-name"> method</span>=&quot;<a class="attribute-value">get</a>&quot;&gt;</span></p> <p><span>Below is what I think you mean.</span></p> <pre class="prettyprint">routes.MapRoute( name: &quot;SearchResults&quot;, url: &quot;SearchResults/{q}/SearchOption/{o}/Page/{p}&quot;, defaults: new { controller = &quot;Search&quot;, action = &quot;Index&quot;, q = UrlParameter.Optional, o = UrlParameter.Optional, p = UrlParameter.Optional } );</pre> <p><span>George<br> </span></p> 2012-04-25T15:19:02-04:004951183http://forums.asp.net/p/1796863/4951183.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>George,</p> <p>If it works, that's exactly what I meant <img class="emoticon" title="Tongue Out" border="0" alt="Tongue Out" src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-tongue-out.gif"></p> 2012-04-25T15:20:43-04:004951225http://forums.asp.net/p/1796863/4951225.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Hi Neil</p> <p>Me thinks they have changed something in the routes, just added this route to MVC3 project in VS2010</p> <pre class="prettyprint">routes.MapRoute( &quot;SearchResults&quot;, &quot;SearchResultsFor/{q}/Option/{o}&quot;, new { controller = &quot;Search&quot;, Action = &quot;Index&quot;, q = UrlParameter.Optional } );</pre> <p>That works as expected, but in VS2011 just does not work</p> <p>George</p> <p>&nbsp;</p> 2012-04-25T15:48:36-04:004960725http://forums.asp.net/p/1796863/4960725.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Hi</p> <p>What's your mean by</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>LearningASP_C_Sharp</h4> That works as expected, but in VS2011 just does not work</blockquote> <p></p> <p>Did this route occurs any error? Or it won't displayed the url as the same with vs2010?</p> <p>Regards<br> Young Yang</p> 2012-05-02T02:48:56-04:004961022http://forums.asp.net/p/1796863/4961022.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Hi Young Yang</p> <p>I get no errors, but route just does not display correctly anymore in VS2011, even when i use old route from VS2010</p> <p>Regards</p> <p>George</p> 2012-05-02T06:59:45-04:004961065http://forums.asp.net/p/1796863/4961065.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p></p> <blockquote><span class="icon-blockquote"></span> <h4>LearningASP_C_Sharp</h4> display correctly anymore </blockquote> <p></p> <p>What's your meaning by this? If you want to go to a view in VS2010, you will get the url, then copy this url into&nbsp;VS2011, it will not display? Then if you want to&nbsp;redirect to&nbsp;this view in VS2011, which url you should enter?</p> <p>Regards<br> Young Yang</p> 2012-05-02T07:19:46-04:004961101http://forums.asp.net/p/1796863/4961101.aspx/1?Re+Problem+with+route+in+VS2011+Beta+Re: Problem with route in VS2011 Beta <p>Hi Young Yang</p> <p>If I open and run old project in VS2010 url is how i expect it, but in VS2011 project url is not displaying how i expect it. Even if i use old route from VS2010 in VS2011 project.</p> <p>I need to go out now, will post further info later today.</p> <p>George</p> 2012-05-02T07:34:36-04:00