tags:

views:

43

answers:

2

My controller method just return String value. When I called JSON from my view page, I don't see any value.

controller method

public string test(int i)
{
    return "Hello world " + i;
}

Inside View,

$.getJSON(['../Feeds/test/', 1, '/'].join(''),
function(json) {
    alert(json.toString());
});

If I run this into Mozilla, I can see "Hello world 1" in response but don't get any alert. What is wrong here?

+1  A: 

because it is not a json object? I am not sure because never try return plain text output with getJSON. why don't try get function?

$.get(['../Feeds/test/', 1, '/'].join(''), 
  function(json) {
   alert(json.toString());
  }
);
Anwar Chandra
+1  A: 

Either make your controller return a JsonResult

return new JsonResult{Data = "Hello world " + i, JsonRequestBehavior = JsonRequestBehavior.AllowGet};

or use jquery's $.get() which doesn't expect a json object.

statenjason