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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:43:36+00:00 2026-05-24T01:43:36+00:00

I want to use BegingForm with Get method and this is what I do

  • 0

I want to use BegingForm with Get method and this is what I do

@using (Html.BeginForm("Search","Home",FormMethod.Get))
{ 
   //My input elements

}

public class HomeController : Controller
{
    public ActionResult Search(string queryString)
    {
    }

}

but query string always comes back as null. I think, I need to do something with route but no luck

routes.MapRoute(
            "SearchRoute", // Route name
            "Home/Search{queryString}", // URL with parameters
            new { controller = "Home", action = "Search", filter = UrlParameter.Optional } // Parameter defaults
            );

Obviously, the coming url to the server is something like

Home/Search?query=”blah”&query2=”blah”&query3=”blah”

What am I doing wrong? What is the correct way to get the query parameters in my controller when I want to use get with beginform?

Also, what if the content of my BeginForm can change and so the query string parameter names could be different depending on the rendered page but I want one Search method that analyze the query string and do the right thing?

Also, is a way for them to query parameters to come in a dictionary?

  • 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-24T01:43:37+00:00Added an answer on May 24, 2026 at 1:43 am

    Obviously, the coming url to the server is something like
    Home/Search?query=”blah”&query2=”blah”&query3=”blah”

    That’s how HTML <form> with method GET works and this has nothing to do with ASP.NET MVC, it’s plain HTML. You can’t do much about it other than having your controller action look like this:

    public ActionResult Search(SearchViewModel model)
    {
        ...
    }
    

    Where SearchViewModel will contain properties for each input field on this form. Also you don’t need this SearchRoute as it won’t work that way.

    This being said you could probably use javascript in order to subscribe for the onsubmit event of the form, cancel the default submission (which exhibits the behavior you are observing currently), manually fetch all the values inside your form and then manually generate the url you want and redirect to it using window.location.href = '....';. I am mentioning this only for completeness but absolutely not as something that I recommend or that you should ever do.

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

Sidebar

Related Questions

Can we use it like this... <% using (Html.BeginForm(PerformSearch, ClientSearch, FormMethod.Post, new { defaultbutton
In my view there is a form shown below <% using (Html.BeginForm(SaveRecords, Search, FormMethod.Post))
I am trying to use the html file input to get the path and
I use The MVC3 Helper to generate my Ajax form like this: @using (Ajax.BeginForm(Attended,
I'd like to use the appropriate HTTP method when possible. In this case, when
I have an Index.cshtml view: @model AttendenceModel @{ Layout = ~/Views/Shared/_Layout.cshtml; } @using (Html.BeginForm(VisOppsummering,
I have the following code in a MVC view: <% using (Html.BeginForm()) { %>
In my ASP.NET MVC application I have the following GET input field: <% using
Got a working AJAX form: @using (Ajax.BeginForm(...)) I want to disable the button while
I want to assign HTML attributes to forms created with Html.BeginForm in ASP.NET MVC

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.