Firstly, change the ajax call to
var a = $('input').val();
var qv = $('.act');
var tv = $('.tot'); // you don't seem to use this
$.ajax({
url: '@Url.Action("DashData", "Home")', // never hard code the url!
type: "POST",
data: { a: a }, // change this
success: function (data) {
// access the properties of the object
var A = data.A; // returns 300
var T = data.T; // returns 1
var P = data.P; // returns 40
var N = data.N; // returns 200
}
});
Side notes:
var a = $('input').val(); will always return the value of the
first <input> in the view, so suggest you use the id attribute
($('#myInput').val();)
- You can also simplify it to
$.post('Url.Action("DashData", "Home"),
{a: a }, function(data) { ... })
Next modify the controller method to accept the parameter your passing and return the matching Map object
public ActionResult DashData(string a)
{
// Get the first matching MapModel
MapModel map = MapData().FirstOrDefault(m => m.R == a);
return Json(map);
}
DashData(){ name : a }but theDashData()method does not even have a parameter namedname. Then all you passing back is an empty list (andqv.val(data.name);makes no sense (typeofList<MapModel>does not contain a property namedname) so a little hard to understand exactly what you wanting to return.