7

I have method like

 UrlHelper.Action("login", "Authentication", HttpContext.Current.Request.Url.Scheme);

I want to pass query string parameter like "referrer?" = pageName to this method. How can I do it?

3
  • 2
    UrlHelper.Action("login", "Authentication", new { referrer = "..." }) Commented Jun 14, 2016 at 10:45
  • Thanks... @Stephen Muecke.. I am trying to get the value of referrer in controller by using code string returnUrl = Request.QueryString["referrer"].ToString(); but it gives me null.. Any help? Commented Jun 14, 2016 at 11:08
  • 2
    Yuu said you want a query string so you method needs to be public ActionResult Login(string referrer) (and the parameter will be bound with the value) Commented Jun 14, 2016 at 11:10

2 Answers 2

5

You just have to decalre your parameter like this:

UrlHelper.Action("login", "Authentication", new { referrer = "Page Name" })

Then get the parameter in your Action:

Request.Params["referrer"]
Sign up to request clarification or add additional context in comments.

Comments

3

Example

Url.Action("GetValues", "Home", new { Area = "Solan", id =Model.Id})

Here Area and id are the parameters passed to the GetValues method inside Home controller

2 Comments

Although this code may answer the question, providing additional context regarding why and/or how it answers the question would significantly improve its long-term value. Please edit your answer to add some explanation.
Is it enough @TobySpeight

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.