Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:31:07+00:00 2026-06-02T05:31:07+00:00

I have done some research and found that I can use: string retUrl =

  • 0

I have done some research and found that I can use:

string retUrl = "";
    if (ViewContext.HttpContext.Request.UrlReferrer != null)
    {
        retUrl =
          ViewContext.HttpContext.Request.UrlReferrer.PathAndQuery;
    }

As a way to set a returnUrl and then pass it into a controller via action link.

However, is there any way I can pass a parameter from a form into a controller?

Here’s how my code looks right now:

@using (Html.BeginForm(new { returnUrl = retUrl})) {
    @Html.EditorForModel()
    <input type="submit" value="Save"/>
}

This works great in the sense that it returns you to the right URL when you submit the form. However, the form doesn’t actually get saved. If I remove that returnUrl parameter it saves the form but it does not redirect properly.

This reason I’m doing this is because this form is accessible from multiple pages and I don’t want to send them all to one page after they submit the form but rather to the previous page.

EDIT

I’ve also tried BeginRouteForm and specifying a controller and action, both approaches did not work.

EDIT

Action source:

[Authorize]
        [HttpPost]
        public ActionResult EditReview(Review review, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return Redirect(returnUrl);
                }
                reviewRepository.SaveReview(review);
                return RedirectToAction("Index");
            }
            return View(review);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:31:09+00:00Added an answer on June 2, 2026 at 5:31 am

    To save you form before redirecting you need to switch some lines around in the action method. Instead of:

    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
         && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
    {
      return Redirect(returnUrl);
    }
    reviewRepository.SaveReview(review);
    return RedirectToAction("Index");
    

    to

    reviewRepository.SaveReview(review);
    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
         && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
    {
      return Redirect(returnUrl);
    }
    return RedirectToAction("Index");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have done some research and found some stuff that may be helpful. I would
I have done some research on the above and found that I am able
I have done some research, and majority of the examples I have found use
I have done some research prior to and have found some great articles but
Ok I am still learning this... I have Googled and done some research but
i have done some learning on struts based on one project that i got.Now
I've done some simple string -> DateTime conversions before using DateTime.ParseExact(), but I have
i have done some code in jquery but where i commented in this bellow
I am starting a new project for a client today. I have done some
I am researching UDID alternatives, and OpenUDID seems interesting. I have done some testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.