TechQA.

Passing object RouteValues to the search button

1.2k views Asked by Piotr P At 2016-09-01T10:05:18+00:00 01 September 2016 at 10:05 2025-10-11T03:21:17+00:00

I would like to pass object RouteValues parameter to that button

<div class="wrapper">
    <div class="search-box">
        <form class="form-inline">
            <div class="form-group">
                <input type="text" name="searchString" value="@Model.searchString" class="search-text form-control" placeholder="Search..."/>
            </div>
            <button type="submit" class="btn btn-info">
                Search
            </button>
        </form>
    </div>
    </div>

I know how to do it with Html.ActionLink, but I don't know where to put it in that button class. Routevalues that I would like to pass look like this:

new { sortOrder = Model.CurrentSort}

Is there any easy way to pass those here to my button?

c# asp.net-mvc frontend routevalues
Original Q&A
2

There are 2 answers

0
Perdido Perdido On 2016-09-01T10:16:36+00:00 01 September 2016 at 10:16

If you need submit form use @Html.BeginForm():

@Html.BeginForm("NAME_METHOD_FROM_YOUR_CONTROLLER", "FORM_METHOD.POST OR GET")
{
    <div class="wrapper">
    <div class="search-box">
    <form class="form-inline">
        <div class="form-group">
            <input type="text" name="searchString" value="@Model.searchString" class="search-text form-control" placeholder="Search..."/>
        </div>
        <button type="submit" class="btn btn-info">
            Search
        </button>
    </form>
    </div>
    </div>
}

All input in your form will send to your controller. Another way if you need use form method get, you can change button to <a> with href attributes: <a href="/Controller_Name/Method/Parameter(optional)" /> the same how your route map.

0
Ankit Sahrawat Ankit Sahrawat On 2016-09-01T11:21:35+00:00 01 September 2016 at 11:21
    @using(Html.BeginForm("action", "controller",
                           new { sortOrder = Model.CurrentSort }, FormMethod.Post, null){

    }

or you can use a hidden field in your form:
<input type="hidden" name="sortOrder" value="@Model.CurrentSort" />

Related Questions in C#

  • How to call a C language function from x86 assembly code?
  • What does: "char *argv[]" mean?
  • User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
  • How to crop a BMP image in half using C
  • How can I get the difference in minutes between two dates and hours?
  • Why will this code compile although it defines two variables with the same name?
  • Compiling eBPF program in Docker fails due to missing '__u64' type
  • Why can't I use the file pointer after the first read attempt fails?
  • #include Header files in C with definition too
  • OpenCV2 on CLion
  • What is causing the store latency in this program?
  • How to refer to the filepath of test data in test sourcecode?
  • 9 Digit Addresses in Hexadecimal System in MacOS
  • My server TCP doesn't receive messages from the client in C
  • Printing the characters obtained from the array s using printf?

Related Questions in ASP.NET-MVC

  • I have a problem outputing the roles on the page ListRoles.cshtml
  • Dropdown list showing SQLServer2005SQLBrowserUser$DONSERVER instead of Active Directory group name in ASP.NET MVC C#
  • Hosting ASP.NET MVC application on IIS web server using Windows 2019 server
  • How to display only department fields associated with a selected department in student automation system?
  • How to send select input data for form submission?
  • Multi level project reference using dll
  • How to upload file to Onedrive using ASP.NET MVC?
  • ASP.NET MVC web app looping between fields only on some devices
  • Is there any automatic job to load AD-groups?
  • How to restrict admin js files to download
  • Download PDF in ASP.NET MVC application
  • How to add bootstrap theme/example into ASP.NET MVC 5?
  • Web API works with Windows authentication enabled when consumed via Swagger but throws an unauthorized issue when accessed through web app
  • ASP.Net Core 7.0 Web App (Model-View-Controller) ErrorViewModel OnGet OnPost do not get called or executed
  • OAuth 2.0 keep getting Authorization has been denied for this request

Related Questions in FRONTEND

  • How to perform CRUD operations on a static JSON array in Angular? (without API)
  • Java and React WebSocket - Error Connection
  • Why can't I use PUT requests?
  • Adding Modules to a Namespace using IIFE
  • How to use PrimeNG multiselect search to trigger an API call based on user search input and populate the multiselect with the retrieved data?
  • Should I compress images in java backend before sending to frontend?
  • Privsate channel doesn;t display messages - propably it's problem with authentication
  • Swiper Js Slider Reveal Next Slider Partially
  • How can i prevent the image from zooming in when i resize the browser?
  • NextJs 14. Intercepting Routes. Modal. Routing Problem
  • How to perform get, update, add and delete operation in a multi-parameter JSON array just like an API in Angular
  • How to animate calculated position/container height when viewport changes?
  • Applying a different position for each child of a parent element with a formula?
  • (React)At rendering, initial value of zustand comesout firstly Please, give me your opinions
  • My state is undefined despite being setted

Related Questions in ROUTEVALUES

  • RouteValues.TryGetValue gives "Local variable 'X' might not be initialized before accessing" error even if the result is true?
  • ASP.NET MVC route values and view model
  • How to get the current url with route values?
  • Route Parameters not working in WebApi
  • Is the RouteValueDictionary class's keys case-insensitive?
  • Passing object RouteValues to the search button
  • How can I pass some objects in ViewBag to the Action? - Preserve search, sort and paging options
  • can we place some data inside the circle drawn on the google map using google map api
  • How do I pass info to route values so I can redirect back after I login Asp.Net MVC
  • Convert a string into routeValues for call RedirectToAction
  • Passing selected button value from view to controller
  • How to work with RouteValues with multiple values of the same name
  • RouteValueDictionary coming across as null in Extension method
  • ActionLink route values containing specific characters
  • How to pass routeValues that contains hyphen via actionlink in asp.net mvc 5

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Popular Tags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
  • Privacy
  • Terms
  • Cookies
  • Homegardensmart
  • Math
  • Aftereffectstemplates