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 8782099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:28:48+00:00 2026-06-13T20:28:48+00:00

I have an application that shows locations on a map. I have created a

  • 0

I have an application that shows locations on a map. I have created a route so that I can have nice hackable URLs, like http://www.mydomain.com/paris. This works fine just typing in the URL, but I have a search form on the home page that sends a GET request. When the form is submitted, the URL displayed in the location bar is in the format http://www.mydomain.com/Dashboard?location=paris. Normally this wouldn’t matter too much as it’s hitting the correct action, but I have a backbone.js application running the show and it’s particular about the URL structure.

It may be impossible to do what I need without javascript or a redirect, because the location isn’t known when the form ACTION attribute is populated – but can anyone confirm?

Here are my routes.

public static void RegisterRoutes( RouteCollection routes )
{
    routes.IgnoreRoute( "{resource}.axd/{*pathInfo}" );
    routes.MapRoute(
        String.Empty,
        "{location}",
        new { 
            controller = "Dashboard",
            action = "Index",
            id = ""
        }
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new
        {
            controller = "Home",
            action = "Index",
            id = UrlParameter.Optional
        } // Parameter defaults
    );

}

Here is the controller.

public class DashboardController : Controller
{
    [HttpGet]
    public ViewResult Index(string location)
    {
        return View(new AccItemSearch { Location = location });
    }
}

Here is the form.

        @using (Html.BeginForm("Index", "Dashboard", FormMethod.Get)) {
                <h2>Where are you going?</h2>
                <input type="text" placeholder="Area, town or postcode" id="location" name="location"/>
                <button>Search!</button>
            </div>
        }

To clarify: the problem I want help with is how to have the user submit the form then land on a page with the URL: http://www.mydomain.com/searchterm and thus match the route, rather than on a page that with the URL http://www.mydomain.com/Dashboard

  • 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-13T20:28:49+00:00Added an answer on June 13, 2026 at 8:28 pm

    You will not be able to change the action attribute of the form during HTML generation (i.e. server side) as you simply don’t know what it should point to. So if you need the URL to end up being the exact search term the easiest bet is probably to change the action attribute to it with JavaScript before the form is submitted, and have a controller that catches all urls that follow the http://www.domain.com/searchterm pattern.

    You can’t really redirect to a specific action because then that would become the URL returned to the browser, and I doubt you want one action per search term.

    HTML:

    <form method="post" id="myform">
        <input type="text" id="searchterm" />
        <input type="submit" value="Search" />
    </form>
    

    jQuery:

    $(function () {
        $("#myform").submit(function () {
            var searchVal = $("#searchterm").val();
            $(this).attr("action", searchVal);
        });
    });
    

    Route:

    routes.MapRoute(
        "",
        "{searchterm}",
        new { controller = "Home", action = "Search" }
    );
    

    Note that this has to be put before the default route(s).

    Action:

    public ActionResult Search(string searchterm)
    {
        //do stuff
    }
    

    Now if a visitor enters the term “Alaska” and submits the search form, they will end up on domain.com/Alaska.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an application that shows one's location on a map. How do
I have an application that shows data from a MySQL table. Basically, my application
I have a application that has an activity that shows message logs. The thing
I have made a view in the application that shows a UITableView. It will
In my Backbone application I have a main view that shows previews of posts.
I have created an app that simply shows the user's current position on a
I have created a simple app which shows a Google Map. I am testing
I'm writing a Windows Phone application that shows a number of locations on a
I have a Silverlight application that displays a map, and my intention is, when
We have an Excel application that I need to maintain that has shown his

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.