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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:02:29+00:00 2026-06-07T14:02:29+00:00

I am trying to adapt the following code $(#artistSearch).submit(function (event) { event.preventDefault(); var form

  • 0

I am trying to adapt the following code

$(“#artistSearch”).submit(function (event) {  
    event.preventDefault();  
    var form = $(this);  
    $.ajax({
        url: form.attr(“action”),
        data: form.serialize(),
        beforeSend: function () {
        $(“#ajax-loader”).show();
    },
    complete: function () {
        $(“#ajax-loader”).hide();
    },
    error: searchFailed,
    success: function (data) {
        $(“#artistTemplate”).tmpl(data).appendTo(“#artist-list”);
    }
});

from Professional ASP.NET MVC 3 to allow searching and returning data within the same form and ended up with the following:

On a separate script file

$(function () {

    $("#btnSearch").click(function (event) {
     event.preventDefault();
    var idno = $("#txtIdNo").value;

     $.ajax({
         url: "/Owner/Search",
         type: "POST",
         data: idno,
         datatype: "json",
         beforeSend: function () {
             $("#FullName").html("");
             $("#OwnerId").html("");
             $("#notFound").html("");
             $("#ajax-loader").show();
         },
         complete: function () {
             $("#ajax-loader").hide();
         },
         error: function () {
             $("#notFound").html("Sorry, no data returned."); ;
         },
         success: function (data) {
             $("#OwnerId").html(data.OwnerId);
             $("#FullName").html(data.FullName);
         }
     });
 });

});

On the Controller

    [HttpPost]
    public JsonResult SearchById(string idNo)
    {
        var owner = _ownerService.FindBy(x => x.IdNo == idNo);
        return  Json(owner);
    }

On the View

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div>
            <p>
               Id No:
               <input type="text" name="txtIdNo"  />
               <input type="button" value="Search" name="btnSearch" />
               <label id="notFound"></label>
            </p> 
        @Html.Hidden("OwnerId")
       .
       .
       .

       <p>
          <input type="submit" value="Create" />
       </p>
    </fieldset>
}

The reason I am using

within the view is to avoid two submit buttons within the same form because I realized the form was validating after clicking on the search button.

I have also looked at the suggested similar questions before asking with no avail.

I have been unable to make the above work and would appreciate any help offered.

I am a newbie to MVC3 and JQuery

  • 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-07T14:02:30+00:00Added an answer on June 7, 2026 at 2:02 pm

    jquery ID Selector (“#id”) – Selects a single element with the given id attribute.

    You are using jquery ID Selector, but you donot have the id attribute on the from elements.

    Add id attribute to your form elements.

    <input type="text" name="txtIdNo"  />
    <input type="button" value="Search" name="btnSearch" />
    
    to 
    
    <input type="text" id="txtIdNo" name="txtIdNo"  />
    <input type="button" id="btnSearch" value="Search" name="btnSearch" />
    

    Edit the jQuery ajax function: data: {idNo:idno}

    $.ajax({
             url: "/Owner/Search",
             type: "POST",
             data: {idNo:idno},
             datatype: "json",
             .........
         });
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to adapt some code that I have found online that uses this
This code was established in a previous post. I'm trying to adapt it to
I am trying to adapt some (to me) very complicated code to work with
I'm trying to adapt this DES encrypting example to AES, so I made the
So I'm trying to adapt this Dropdown menu on Joomla the styles work great
I'm trying to adapt my code with json in google maps. I tried looking
i am trying to make sense of the following result. The test case code
I'm following Justin Slattery's Plugin Architecture tutorial and trying to adapt it for Razor,
I'm currently trying to adapt some sample code and have hit a snag when
I have the following. I am trying to trigger the function based on the

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.