I have a non-mvc application that needs to dynamically populate a select list, so I have a separately running MVC application to provide the data.
My MVC controller seems to be set up correctly:
public JsonResult GetStateList()
{
var list = new List<ListItem>() {
new ListItem() { Value = "1", Text = "VA" },
new ListItem() { Value = "2", Text = "MD" },
new ListItem() { Value = "3", Text = "DC" }
};
return Json(list, JsonRequestBehavior.AllowGet);
}
And when I type the URL http:/localhost/TestMVC/home/GetStateList into the browser I get the JSON response.
The problem is when I am trying to use a $.get() from within the other program. My code is below and I know it’s not hitting the controller since I am in debug mode and nothing hits. Is my syntax incorrect? Should I be calling it differently?
$('#GetEmployeesByLetter').click(function() {
var url = "http:/localhost/TestMVC/home/GetStateList";
$.get(url, {}, function(data) {
alert(data);
});
});
Have you tried
Two dashes after http – (//)
Anyway, you should never specify url like that, better to have root url,