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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:54:08+00:00 2026-06-06T14:54:08+00:00

Here is my JsonResult in my controller: // // GET: /Home/GetTags/ public JsonResult GetTags()

  • 0

Here is my JsonResult in my controller:

//
// GET: /Home/GetTags/

public JsonResult GetTags()
{
    List<string> Tags = Db.Tags.Select(t => t.Name).ToList();

    return Json(Tags, JsonRequestBehavior.AllowGet);
}

Here is what the data looks like if I browse to /Home/GetTags:

["Author","Movie","Video Game","Website","Republican","Democrat"]

Here is the jQuery function in my view:

<script type="text/javascript">
$(function() {
    function split(val) {
        return val.split(/,\s*/);
    }
    function extractLast(term) {
        return split(term).pop();
    }
    $("#Tags")
        // Don't navigate away from the field on tab when selecting an item
        .bind("keydown", function(event) {
            if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
                event.preventDefault();
            }
        })
        .autocomplete({
            source: function(request, response) {
                $.getJSON("@Url.Action("GetTags")", {
                    term: extractLast(request.term)
                }, response);
            },
            search: function() {
                // Custom minLength
                var term = extractLast(this.value);
                if (term.length < 2) {
                    return false;
                }
            },
            focus: function() {
                // Prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var terms = split(this.value);
                // Remove the current input
                terms.pop();
                // Add the selected item
                terms.push(ui.item.value);
                // Add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
});
</script>

Copied the jQuery from jQuery UI website. It was working fine with static data. The JsonResult doesn’t seem to be called at all. When I put a breakpoint in it and debug it, it never hits the breakpoint.

  • 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-06T14:54:09+00:00Added an answer on June 6, 2026 at 2:54 pm

    Apparently, the “Custom minLength” was the problem (ie the “search” property of the “autocomplete()” function call. Here’s the revised jQuery:

    <script type="text/javascript">
    $(function() {
        function split(val) {
            return val.split(/,\s*/);
        }
        function extractLast(term) {
            return split(term).pop();
        }
        $("#Tags")
            // Don't navigate away from the field on tab when selecting an item
            .bind("keydown", function(event) {
                if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
                    event.preventDefault();
                }
            })
            .autocomplete({
                source: function(request, response) {
                    $.getJSON("@Url.Action("GetTags")", {
                        term: extractLast(request.term)
                    }, response);
                },
                focus: function() {
                    // Prevent value inserted on focus
                    return false;
                },
                select: function(event, ui) {
                    var terms = split(this.value);
                    // Remove the current input
                    terms.pop();
                    // Add the selected item
                    terms.push(ui.item.value);
                    // Add placeholder to get the comma-and-space at the end
                    terms.push("");
                    this.value = terms.join(", ");
                    return false;
                }
            });
    });
    </script>
    

    Also, I revised the JsonResult in the controller like so, to provide only the values that matched what the user typed in the box:

    //
    // GET: /Home/GetTags/
    
    public ActionResult GetTags(string term)
    {
        List<string> Tags = Db.Tags.Select(t => t.Name).Where(n => n.Contains(term)).ToList();
    
        return Json(Tags, JsonRequestBehavior.AllowGet);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a controller like this: [HttpPost] public JsonResult FindStuff(string query) { var
I have a json string in an action of MVC controller. I want to
I have controller action which returns JsonResult and is consumed by jquery ajax get
How can I return custom validation messages using JsonResult and AJAX? Here is my
I have the following controller code that returns a Json list object to my
Trying to create a list to return some JSON data to a view. Following
I would like to get JSON result from another Controller and pass it back
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
The problem here is pretty self-evident from the resulting JSON array at the bottom.
I have a model like this: public PurchaseOrder { [Required] [StringLength(15)] public virtual string

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.