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

0

4 Answers 4

3

Use:

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

See this answer for more details.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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>

Comments

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)
{
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.