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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:30:19+00:00 2026-05-11T20:30:19+00:00

I have some data which I am formatting like this: // … imagine populating

  • 0

I have some data which I am formatting like this:

 // ... imagine populating a SqlDataReader with some results ...
 var results = new StringBuilder();
 while (reader.Read())
 {
     results.AppendFormat("{0}, {1}\n", reader["name"], reader["emailAddress"]);
 }
 return results.ToString();

My controller action is pretty simple:

 public ActionResult Find(string q)
 {
     var users = Customer.Search(q);
     return Content(users);
 }

And my javascript in the view looks like this:

 $(document).ready(function() {
     $("input#user").autocomplete('<%= Url.Action("Find", "Customer") %>', {
         minChars: 2,
         width: 500,
         matchContains: true,
         autoFill: false,
         formatItem: function(row, i, max) {
             return i + "/" + max + ": (" + row[0] + ") " + row[1];
         },

         formatMatch: function(row, i, max) {
             return row[0];
         },

         formatResult: function(row) {
             return row[1];
         }
      });
    });

Question A

I am using the Autocomplete from here. At this point I am having an issue where I cannot get the two fields to read as separate values. For example, if a rows name field is “John” and its email field “john@doe.com” I would expect those to show up in row[0] and row1 respectively. However, they currently I get “John, john@doe.com” in row[0] and row1 is undefined.

What do I need to change (either in the javascript or the method where I’m building the string) to get row[0] and row1 to show the proper data?

Question B

I would prefer to have the data in the rows named. By this I mean:

 formatItem: function(row, i, max) {
     return i + "/" + max + ": (" + row.name + ") " + row.email;

I struggled for a while to format my data so this would happen but I was never successful. How would I format my data so that the AutoComplete would understand this?

  • 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-11T20:30:19+00:00Added an answer on May 11, 2026 at 8:30 pm

    If you create a list of results of a class with Name and Email properties, then return it as JSON, then I think it will work the way you want it to.

    Intermediate class

    public class AutocompleteResult
    {
        public string Name { get; set; }
        public string Email { get; set; }
    }
    

    Search code:

    var results = new List<AutocompleteResult>();
    while (reader.Read())
    {
        results.Add( new AutocompleteResult
                         {
                             Name = reader["name"],
                             Email = reader["email"]
                         });
    }
    return results;
    

    Action:

    public ActionResult Find(string q)
    {
        var users = Customer.Search(q);
        return Json(users);
    }
    

    View:

    I think… the key difference is the parse method and the dataType, you might have to adjust the parse method, et. al. to get the formatting right. You might be able to get rid of formatResult/formatMatch, but I’m not sure. I don’t use these and as I recall what I’m doing in parse sets the values properly. I’m trying to keep your basic code, but as I said I don’t use all the methods that you do and haven’t explored them in depth.

    $(document).ready(function() {
        $("input#user").autocomplete('<%= Url.Action("Find", "Customer") %>', {
            dataType: 'json',
            minChars: 2,
            width: 500,
            matchContains: true,
            autoFill: false,
            parse: function(data) {
               var array = new Array();
               for (var i = 0; i < data.length; ++i) {
                  var datum = data[i];
                  array[array.length] = {
                              data: datum,
                              value: datum.Name,
                              result: dataum.Email
                  };
               }
            }
            formatItem: function(data, i, max) {
                return i + "/" + max + ": (" + data.Name + ") " + data.Email;
            },
            formatMatch: function(data, i, max) {
                return data.Name;
            },
            formatResult: function(data) {
                return data.Email;
            }
         });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have some data which I am formatting like this: // ... imagine populating
I have been tasked with creating a reusable process for our Finance Dept to
I am total noob with XSL and XSL-FO and I am looking for some
I'm doing some maintenance coding on a webapp and I am getting a javascript
We have a large application mainly written in SQL Server 7.0, where all database

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.