0

There is a method to pass the entire query string to another page using the a tag in .NET Core 3.1?

I tried this:

<a asp-action="VerifiedAll" asp-route="@Context.Request.QueryString.Value" 
   class="btn btn-manage">Verified All</a>

But I get an error, it could not create the href property using this

3
  • .NET Core 3.1 reached End Of Life last year. That means there's absolutely no support for it any more, not even security fixes. You shouldn't be writing any new code targeting 3.1 The current Long Term Support version is .NET 6, supported until November 2024 Commented May 25, 2023 at 7:07
  • I know .NET Cose 3.1 has no support any more, but the company I'm working for decided to use this version for this project :( Commented May 25, 2023 at 15:39
  • Hello have you tried the solution provided? Is there anything else that I can help you on this? Commented May 30, 2023 at 6:25

1 Answer 1

0

There is a method to pass the entire query string to another page using the a tag in .NET Core 3.1? But I get an error, it could not create the href property using this

Based on your shared code and description its not very clear that what exactly you are trying to achieve.

Usually, asp-route attribute is used for creating a URL linking directly to a named route but for that your syntax were not correct. If you would like generate href than you should do as following:

<a asp-route="QueryStringValue" class="btn btn-success">Verified All</a>

enter image description here

Explanation:

public class QueyStringController : Controller
    {
        [Route("QueyString/VerifiedAll", Name="QueryStringValue")]
        public IActionResult VerifiedAll()
        {
            return View();
        }
    }

As you can see I have used QueryStringValue as route name which I am passing in asp-route in order to generate <a> or href tag.

But if you do otherwise, you would encounter following error.

enter image description here

How to pass query string in other page:

Actually, using numerous way, you can pass query string to another page on of the way you can implement is from controller redirection.

public IActionResult PassQueryString()
        {

          return RedirectToAction("Index", "Home", new { test="MyQueryStringvalue"});
        }

Above, redirection, will call Index action of Home controller and will pass Test query string with MyQueryStringvalue as value. You can now extract the value from your HttpContext.

<a asp-controller="QueyString" asp-action="VerifiedAll" asp-route-id="@Context.Request.QueryString.Value"
   class="btn btn-manage">Verified All</a>

enter image description here

Output:

enter image description here

Note: You can have a look at our official document here for more details.

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

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.