2

I have controller like this:

public ActionResult Load(Guid? id)
{
   ...
}

When load the view like /Report/Load it load the page.

Then I click on link on page to load one item /Report/Load/7628EDFB-EFD5-E111-810C-00FFB73098ED and it loads the page fine.

Now I want to redirect again to /Report/Load using this url.action

<a href="@Url.Action("Load", "Report")">Close Report</a>

But it keeps redirecting me to /Report/Load/7628EDFB-EFD5-E111-810C-00FFB73098ED

What I need to do on URL.Action to redirect me to page with the id?

Tried without success:

<a href="@Url.Action("Load", "Report", null, null)">Close Report</a>

Thanks

KleberBH
  • 452
  • 1
  • 9
  • 28

4 Answers4

3

Use:

<a href="@Url.Action("Load", "Report", new { id = null })">Close Report</a>

See this answer for more details.

Community
  • 1
  • 1
Beyers
  • 8,968
  • 43
  • 56
1

I got it fixed by following answer from johnnyRose and Beyers.

The result is

<a href="@Url.Action("Load", "Report", new { id = "" }, null)">Close Report</a>

Thanks a lot.

KleberBH
  • 452
  • 1
  • 9
  • 28
0

I can't seem to find issue with your code. But Can't you simply set the URL in the model when trying to load the specific item. In the load function inside the controller do something like this:

var urlBuilder =
new System.UriBuilder(Request.Url.AbsoluteUri)
    {
        Path = Url.Action("Load", "Report"),
        Query = null,
    };

   Uri uri = urlBuilder.Uri;
  string url = urlBuilder.ToString();
  YourModel.URL = url;

In your view.cshtml do something like

  <a href="@Model.URL " target="_blank">reports</a>
Arun Kumar
  • 907
  • 13
  • 33
0

You should have looked up in your vs's intellisense-

As it accepts arguments- ActionName,ControllerName,RouteValues

enter image description here

Where routeValues is the third argument that is object type and it accepts route values i.e. new{id=9,name="foobar"}

Where method would be like-

[HttpGet]
Public ActionResult Get(int id, string name)
{
}
Manoz
  • 6,507
  • 13
  • 68
  • 114