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

  • Home
  • SEARCH
  • 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 6238685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:15:30+00:00 2026-05-24T11:15:30+00:00

I have simple controller: public class TestController : Controller { public ActionResult Test(string r)

  • 0

I have simple controller:

public class TestController : Controller
    {
        public ActionResult Test(string r)
        {
            return View();
        }

    }

I have simple View Test.cshtml:

<h2>@ViewContext.RouteData.Values["r"]</h2>
        @using (Html.BeginForm("Test", "Test"))
        {
            <input type="text" name="r" />
            <button>Submit</button>
        }

I have route rule in Global.asax:

routes.MapRoute(
            null,
            "Test/{r}",
            new { action = "Test", controller = "Test",
                r = UrlParameter.Optional }
        );

I want to make such thing: user types route value in input, press submit and controller redirects him to page Test/value. But controller show just page with name Test everytime. ViewContext.RouteData.Values[“r”] is empty too. I check in debug, Test action recieves user value of r correctly.
How can I realize my idea?
Thanks.

  • 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-05-24T11:15:31+00:00Added an answer on May 24, 2026 at 11:15 am

    You cannot do this without javascript. There are two types of methods that exist when submitting a <form>: GET and POST. When you use POST (which is the default), the form is POSTed to the url but all data entered in input fields is part of the POST body, so it is not part of the url. When you use GET, the input fields data is part of the query string but of the form /Test?r=somevalue.

    I wouldn’t recommend you trying to send user input as part of the path but if you decide to go that route you could subscribe to the submit event of the form and rewrite the url:

    $('form').submit(function() {
        var data = $('input[name="r"]', this).val();
        window.location.href = this.action + '/' + encodeURIComponent(data);
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple test application: Model: public class Counter { public int Count
I have a simple controller which returns images: public class ImageController : Controller {
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
I have a really simple action in a controller that simply returns a view
I have a simple little test app written in Flex 3 (MXML and some
I have a simple controller like this (no, not really, but let's say I
I have a base controller class that attempts to look at Request.ContentType to see
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement

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.