[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Asp.net mvc 5

Posted on 2016-11-29
5
Medium Priority
?
90 Views
Last Modified: 2016-11-29
hi Guys,

I have mvc application and I implemented autocomplete that return params with ajax:

see my code:
 $("#Search").autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            url: "/Categorymanager/Autocomplete",
                            type: "POST",
                            dataType: "json",
                            data: { Prefix: request.term },
                            success: function (data) {
                                response($.map(data, function (item) {
                                    return {
                                        label: item.Deptname + item.Categoryname,
                                        Value: item.Value
                                    };
                                }))
                            }
                        })
                    },

                    minChars: 2,
                    minLength: 2,
                    autoFill: true,
                    select: function (event, ui) {
                        $("#Search").val(ui.item.Value);
                        return false;
                    },
                    messages: {
                        noResults: "", results: ""
                    }
                }).data("ui-autocomplete")._renderItem = function (ul, item) {
                    return $("<li></li>")
                    .data("item.autocomplete", item)
                    .append("<div><strong style='color:red;'>" + item.label + "</strong><strong style='color:blue;'>" + "|" + " " + item.Categoryname + "</strong></div>")
                    .appendTo(ul);
                }
                

            });
        });

Open in new window


After I'm getting the value into the text box I would like to click on the GO button and send this value to the controller with ajax.
Here is my text:
Capture.JPG
Can somebody give me an idea how to do it.
0
Comment
Question by:Moti Mashiah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 41906543
What about the following ?
$("#GO_button_ID").click(function() {
   $.post("/path/to/controller", { search:$("#Search") }, function(result) {
       alert(result);
   }, "json");
});

Open in new window

0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 41906557
yes, that could be a good idea, but look at my autocomplete is return just one value to the textbox $("#Search").
I want to show in my textbox just one value but return 4 values to the method you just posted.

look at this code in my autocomplete method:
select: function (event, ui) {
                        $("#Search").val(ui.item.Value);
                        return false;
                    },
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 41906563
this is my server side code:
public JsonResult Autocomplete(string Prefix)
        {
            ALThompsonCRMEntities ald = new ALThompsonCRMEntities();
            RMSmasterHQEntities db = new RMSmasterHQEntities();

            var search = ald.CatManSearchAutocomplete(Prefix)
                .Select(a => new Searchresult
                {
                    Deptname = a.DeptName,
                    Categoryname = a.CategoryName,
                    Value = a.DeptName
                }).ToList();

            return Json(search, JsonRequestBehavior.AllowGet);
        }

Open in new window


I can return more than one value to the property value, but I don't want to show more than one value in the textbox.

I hope you got my point.

THanks,
0
 
LVL 82

Expert Comment

by:leakim971
ID: 41906622
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 41906655
thx
1

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question