I am trying to do an ajax call from my view where I return a json object from my controller. However, when I try this I get the object type, but not the values as strings. Here is my code..
Controller
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public ActionResult GetPerson()
{
var _model = _person;
return Json(_model, JsonRequestBehavior.AllowGet);
}
static Person _person = new Person()
{
FirstName = "Steve",
LastName = "Johnson",
Age = 27
};
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-2.0.3.min.js"></script>
</head>
<body>
<div>
<form>
<fieldset>
<legend>The Person</legend>
<label>Name: </label>
<input />
<label>Age: </label>
</fieldset>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: '/Home/GetPerson',
type: 'GET',
success: function (result) { alert(result);}
});
});
</script>
The alert box return [object Object]. I am trying to get the string values of the "Person" object.
Any help would be appreciated.
Thanks!