Javascript/JSON displaying data from controller

ted231231

New Member
I am having trouble working with the javascript to display data connecting my api controller with models. The trouble i am having is with my success statement:JavaScript\[code\]<div>Name: <span id="name"></span></div><div> Email: <span id="email"></span></div><script type ="text/javascript" src="http://stackoverflow.com/questions/15696438/~/Scripts/jquery-1.9.1.min.js"></script><script type ="text/javascript"> getRoleUser(9, function (roleUser) { $("#name").html(roleUser.Name); $("#email").html(roleUser.Email); }); function getRoleUser(id, callback) { $.ajax({ url: "/api/RoleUser", data: { id: id }, type: "GET", contentType: "application/json;charset=utf-8", statusCod: { 200: function (roleUser) { callback(roleUser); }, 404: function () { alter("Not Found!"); } } success: ???// trouble in how to write it } }); }</script>\[/code\]Model\[code\]public partial class RoleView{ public RoleView() { this.Users = new HashSet<RoleUser>(); } public ICollection<RoleUser> Users { get; set; }}public class RoleUser{ public string Name { get; set; } public string Email { get; set; }}\[/code\]Controller\[code\]public class RoleApiController : ApiController{ private RoleService _roleService = new RoleService(); public RoleUser GetRoleUser(int sectionID) { if (sectionID != null) { return _roleService.GetUsers(sectionID); } throw new HttpResponseException(HttpStatusCode.NotFound); }}\[/code\]I am not even sure if my java script is properly returning JSON or which way is better. My intention is to return a list that will display user's name and email address and later on hopefully add in an a thumbnail image. thanks for any help
 
Back
Top