Search code examples
htmlasp.net-mvc-4razorhref

href is truncating querystring


I have following querystring in a variable

var redirectTo = "http://localhost/DGS.DGSAPI.UI/ORDERONLINE?addr=10 n main&apt=&zip=44408&customer=N";

rendered on View like:

<a href=@redirectTo>Check Here</a>

But when it renders, it truncates after it found a space. It rendered following:

http://localhost/DGS.DGSAPI.UI/ORDERONLINE?addr=10

What is wrong?


Solution

  • Use quotation marks, without it a space will make the browser think that a new attribute is starting:

    <a href="@redirectTo">Check Here</a>
    

    Also note that spaces inside querystring parameters are normally encoded as + symbols. So even with the added quotes, it could still be that the URL won't work correctly when opened.