EdisonCP / sharp-architecture

Automatically exported from code.google.com/p/sharp-architecture
Other
0 stars 0 forks source link

BuildUrlFromExpressionForAreas<>() #134

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use the Html.BuildUrlFromExpressionForAreas<>() method with an action
expression using multiple parameters.  For example in the Northwind web
site example \Views\Home\Index.aspx line;
<%= Html.BuildUrlFromExpressionForAreas<CustomersController>(c =>
c.Create("Some_Company_Name", "A_5_Character_Unique_ID")) %>

What is the expected output? What do you see instead?
The expected output should be:
/Customers/Create?companyName=Some_Company_Name&assignedId=A_5_Character_Unique_
ID

Instead I see;
/Customers/Create?companyName=Some_Company_Name&amp;assignedId=A_5_Character_Uni
que_ID

The ampersand in the query string has been replaced with an '&amp;'
character reference, which isn't valid as a separator in a URL query
string.  Note that you have to look at the page source, as the web browser
will display the query string '&amp;' properly, but this doesn't work as a URL.

What version of the product are you using? On what operating system?
1.0.0.0 (r486) WinXP SP3, VS2008 SP1, .Net 3.5 SP1

Please provide any additional information below.
I believe this change to SharpArch.Web\Areas\LinkForAreasExtensions.cs will
fix the problem:
    private static string GetQueryStringArguments<TController>(HtmlHelper
helper, Expression<Action<TController>> action, string linkText) where
TController : Controller {
        //RouteValueDictionary routingValues =
ExpressionHelper.GetRouteValuesFromExpression(action);
        //string routeLinkFromMvc = helper.RouteLink(linkText, routingValues);

        //string routePortion = GetRoutePortionFrom(routeLinkFromMvc);

        RouteValueDictionary routingValues =
ExpressionHelper.GetRouteValuesFromExpression<TController>(action);
        string routePortion =
helper.RouteCollection.GetVirtualPath(helper.ViewContext.RequestContext,
routingValues).VirtualPath;

        if (routePortion.IndexOf('?') > -1) {
            return routePortion.Substring(routePortion.IndexOf('?'));
        }
        else {
            return "";
        }
    }

Enjoy...
Dan

Original issue reported on code.google.com by sonom...@gmail.com on 21 Oct 2009 at 3:46