3

I have a problem by Url.Action in asp.net MVC. this is a sample:

Url.Action("index", new { page = 1, success = 2});

This code generate this url index?page=1&success=2 In this url there is & instead of & character. because of this problem Request.QueryString["success"] return null. What is the solution? Note: Im using Url.Action and Request.QueryString in a view not a controller.

Ghooti Farangi
  • 19,926
  • 15
  • 46
  • 61

2 Answers2

4

Problem is encoding

You're probably using <%: %> but you should be using <%= %> so result will not get encoded.

So instead of writing:

<a href="<%: Url.Action("index", new { page = 1, success = 2}) %>">My link</a>

you should convert to:

<a href="<%= Url.Action("index", new { page = 1, success = 2}) %>">My link</a>
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
1

You are probably html-encoding the output of the Url.Action.

Can you post code about where and how you use the result? Because the method itself should return the value as you expect it.

Dirk van Bergen
  • 245
  • 2
  • 10