tags:

views:

293

answers:

4

When using Html.ActionLink passing a string containing the # char renders it like it is but if you UrlEncode it renders as %2523.

I believe it's a bug. MVC Beta Release.

Is it really a bug?

http://example.com/test# is rendered as

http://example.com/test%2523 instead of

http://example.com/test%2523

A: 

Is HttpUtility.UrlEncode the same as Server.UrlEncode? (HttpContext.Current.Server.UrlEncode)

I cannot do a check right now, not near a .NET machine.

Redbeard 0x0A
A: 

Yes it does, run the following Console application and see what it outputs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string hash = "#";
            Console.WriteLine(HttpUtility.UrlEncode(hash));
        }
    }
}
Turnkey
+1  A: 

ok, found the problem... I'm using MVC, and the Html.ActionLink outputs # if I don't use UrlEncode, but if I do, it outputs %2523 which is %23 encoded....

maybe it's a bug?

thanks!

Glad you found the problem - could you please edit your question to make it match the problem more, something like "URL encoding with MVC", would be nice to have the issue documented so others can benefit.
David Hall
A: 

changed the question...