Im trying to make a single view crud operation on ASP.NET MVC and having trouble getting data from ajax call and display it on a input field.
here the json actionresult
heres the ajax call
heres the data result
how can i extract that data and display it to an input field
i try this but nothing workds
According to your codes, you return the json return Json(new { data = objplan });
, and your planid is not inside a list of objects.
So you should could directly use the data.data.planid, it will return the right value, more details, you could refer to below codes:
ASP.NET CORE:
public IActionResult GetPlan(int id) {
Plan objplan = new Plan { planID = 1, Price =1 };
return Json(new { data = objplan });
}
public class Plan {
public int planID { get; set; }
public int Price { get; set; }
}
Ajax:
function getplanbyid(planid) {
$.ajax({
url: "/home/getplan?id=" + planid,
type:"get",
success: function (data) {
console.log(data.data.planID);
}
});
}
Result: