What is the process for setting up an automatic submission for the "Search" feature?

My Perspective:

@using (Html.BeginForm())
{
    <p id="a">
        Search for VCMEMBRE/VCPARENT: @Html.TextBox("SearchString") 
        <input type="submit" name="searchType" value="Find!" />
    </p>
}

My Handler:

public ActionResult Index(string searchString)
{
    if (!String.IsNullOrEmpty(searchString))
    {
        axeModel.trcubezonequotas = db.TRCUBEZONEQUOTAS.Where(
            (s =>
                   s.VCMEMBRE.ToLower().Contains(searchString.ToLower())
                || s.VCPARENT.ToLower().Contains(searchString.ToLower())
            )
        );
        return View(axeModel);
    }

Answer №1

Here is an example of how to accomplish this task:

Firstly, in your HTML tag, assign a function to the onChange event:

<input type="text" id="search" onchange="myFunction()" name="searchType" value="Find!" />

Next, define the function that will call your controller method:

For instance:

function myFunction(){
var searchterm = $("#search");
$.get( "your controller url", { searchString: searchterm} )
  .done(function( searchResults) {
    searchResults.each(function( index ) {
       console.log( index + ": " + $( this ).text() );
    });   
  });
}

Answer №2

Good day!

I am greatly appreciative of your assistance.

I've made some changes to the code, here it is :

My Perspective:

        @using (Html.BeginForm())
        {
         <p id="a">
        <input type="text" id="search" onchange="myFunction()"  name="searchType" value="Find!" /> 
          </p>
        }

    <script type="text/javascript" language="javascript" >
    function myFunction(){
    var searchterm = $("#search");
    $.get( "Index","SaisieReferentiel", { searchString: searchterm} )
      .done(function( searchResults) {
        searchResults.each(function( index ) {
           console.log( index + ": " + $( this ).text() );
        });   
      });
    }
    </script>

My Controller:

  public class SaisieReferentielController : Controller
    {
    public ActionResult Index(string searchString)
    {
        if (!String.IsNullOrEmpty(searchString))
        {
            axeModel.trcubezonequotas = db.TRCUBEZONEQUOTAS.Where(
                (s =>
                       s.VCMEMBRE.ToLower().Contains(searchString.ToLower())
                    || s.VCPARENT.ToLower().Contains(searchString.ToLower())
                )
            );
            return View(axeModel);
        }
}

However, there seems to be an issue with my JavaScript code: JavaScript runtime error: Object does not support the property or method "each"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting up Node JS with the essentials

Recently, I successfully installed Node JS on my EC2 instance (server) by following the detailed guide provided on this helpful website: After completing the installation process as per the instructions, I attempted to implement Node in my project. Howeve ...

Create type definitions for React components in JavaScript that utilize the `prop-types` library

Exploring a component structure, we have: import PropTypes from 'prop-types'; import React from 'react'; export default class Tooltip extends React.Component { static propTypes = { /** * Some children components */ ...

Utilizing the dollar shorthand for jQuery in conjunction with Selenium

While utilizing the Selenium addon along with jQuery in my project, I encountered an issue where the use of jQuery functions containing $ in Selenium would trigger a "function not found" error. The problem was resolved by removing jQuery, but using jQuer ...

Formatting dates in JavaScript

When using the jQuery datepicker, my goal is to set a minimum and maximum date range for users to select from. I also need to ensure that the date format is based on the user's locale. In this case, there are two date fields: Start date and End date. ...

Passing a ref from a parent component to a child component in reactjs

I have the following situation, how can I make sure that the attachment field in the child component is accessible from the parent component? class ServiceDeskCustomerCreate extends Component { constructor(props, context) { super(props, context); ...

Struggling to locate a straightforward sidebar solution without relying on Bootstrap. Finding an easy-to-use answer seems

I have a lightweight and easy-to-understand code for a website project with two panels. The first panel on the left is a large navigation (270px width, top to bottom, similar to a wiki) with approximately 30 unordered list items. Next to it is the second ...

Determine the location of an image with the help of Jquery

I'm currently working on finding the position of an image with Jquery. The issue I am facing is that it only provides me with the initial position of the image when the document was loaded. $(".frog").click(function(){ alert($(".frog").position() ...

Unlocking React Event Handlers using Puppeteer

I'm struggling to fully comprehend my request, and I'm seeking clarification. I am currently working on scraping a website using Puppeteer in NodeJS. So far, I have managed to select the necessary element and access its properties. However, I am ...

Javascript isn't being executed by Internet Explorer as expected

I'm currently working on a web application that requires backend processing while simultaneously showing the information on the screen. AJAX seems like the ideal solution, so I've implemented it in my project. However, before initiating the AJAX ...

What is the best approach to configure Nuxt.js to recognize both `/` and `/index.html` URLs?

Currently, I have set up my Nuxt.js in default mode with universal and history router configurations. After running nuxt generate, the generated website includes an index.html file in the dist folder. This means that when the website is published, it can ...

Update or Delete BreezeJS EntityManager After Losing Instance Reference

In the process of developing a CRM application with a single-page application structure, I am integrating BreezeJS and AngularJS. The implementation involves utilizing dynamically-generated tabs to display various modules. Each time a user clicks on a menu ...

How to make Sails.js package accessible across all modules

Recently, I have been using Sails frequently and came across a common practice question. Whenever I need to use a specific NPM package multiple times in a project, I typically include it in my config/bootstrap.js file like this: module.exports.bootstrap = ...

Transmission of data between tabs within an AJAX tab container in ASP.net

In my ASP.net application, I have implemented tabpanels on a page. When a user clicks the submit button while on the first tab, the second tab control is displayed. Ontabindexchanged event, I am dynamically generating a usercontrol and passing values to it ...

The impact of React-router's history within the connect function of the react-redux provider

After successfully connecting my presentational-functional component to the redux store using the connect function, I encountered an issue regarding redirection upon triggering the getTask action or when apiGetTask has completed. I attempted to implement t ...

How can the jsoncallback argument enhance the functionality of .getJSON()?

I've noticed that in a lot of example code, the format of .getJSON() looks something like this: $.getJSON("url?jsoncallback=?", function(data){ ...} On the back-end, the response is typically written as follows: $response = $_GET["jsoncallback"]." ...

What is the solution for handling undefined errors that occur when employing d3.select(this) within a Vue methods hook?

Currently, I am in the process of transferring d3 graphs from another project to my personal Vue-based project. Most aspects are functioning as expected, except for aligning labels in the arcs of a pie chart using the arc.centroid(d) method. Two errors kee ...

Using Ajax to send data to a model within another model in ASP.NET Core MVC

I'm new to this platform and I'm curious about sending model data within another model from ajax to controller. Here are my models: public class mfItems { [Key] [Display(Name = "Item ID")] public string ItemID { get; set; } ...

The jQuery .on("change") function keeps triggering repeatedly, but I'd like it to only execute once

I'm currently working on a feature that involves detecting changes to input text fields. Every time the user makes a change in an input field, I need to capture the new value and validate it. However, I've noticed that the code I have implemented ...

Form values not being transmitted correctly in Ajax POST request

I'm facing an issue with my form submission through AJAX where the values are coming out incorrect. Strangely, when I use a normal POST submit it works perfectly fine! <script type="text/javascript"> $(function () { $('#B ...

The jQuery date picker is showing an error with the function daySettings[2].replace, indicating that

Encountering a problem with the jQuery version I am using: <script src="js/Common/jquery-2.1.1.min.js" type="text/javascript"></script> <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> The code I have writte ...