Click here to Skip to main content
15,113,970 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using autosearch textbox in layout page & jquery code jason method call in controller,I am able to autosearch dynamic values from database in home page but when value is selected and redirected to specific page there autosearch is not working(jquery is not calling to jason method).I tried also removing other javascript files and taking a new view file.
("Autosearch textbox is working in home page but when it is redirected to another view Auto search is not happening in textbox.")
Hi saineshwar,i checked through console and the problem is it is not correctly routing to controller and action.below is my routing order.please check it.
 var uri = "Home/GetCountry";
<http://localhost:1673/Products/Home/GetCountry?countryName=s Failed to load resource: the server responded with a status of 404 (Not Found)

I have put autosearch in layout page and from where ever move to different views i should redirect to 'home'-controller and 'getcounrty'- jason method.Suggest with correct routing order.Thank you

What I have tried:

my jquery code:

var textbox;
var selectValue;

$(function () {

textbox = $("#txtCountrty");
selectValue = $('ul#selectedValue');

textbox.on("input", function () {
function getAutoComplete(countryName) {
var uri = "Home/GetCountry";

$.getJSON(uri, { countryName: countryName })
.done(function (data) {

var count = 0;
$.each(data, function (key, item) {

var li = $('<li/>').addClass('ui-menu-item').attr('role', 'menuitem')
.html("&lt;a href='' onclick=\"setText('" + item + "')\">" + item + "</a>")

function setText(text) {

jason method:

public JsonResult GetCountry(string countryName)

    MySqlConnection Con = new MySqlConnection(ConfigurationManager.ConnectionStrings["Mysqlcon"].ConnectionString);

    DataTable dt;

    var ds = new DataSet();
Updated 25-Jan-17 6:55am
You are just setting some text on click of the item selected. I don't see any other code to redirect and show some other page.

What is the exact issue?
Saineshwar Bageri 25-Jan-17 5:51am
Please have a look into browser console is there any error you are getting in it ?

1 solution

var uri = "Home/GetCountry";

That means to access GetCountry in a sub folder of the current uri called Home. So if you are at the root of the site you are at "/" so it accesses "/Home/GetCountry" which is right. If you are in, say, "Product/Detail" then it will try and access "Product/Details/Home/GetCountry" which is wrong.

Use @Url.Action to get a valid url for the action you are calling (google for syntax) or failing that just add the forward slash to the url

var uri = "/Home/GetCountry";

which means always look in root for Home.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900