0

I have some issues with displaying data as a Json object in this ASP.NET Web API project. It is my first try, I don't have Views, I am gonna use Postman for testing. Can you give me some diretions how to display the model as an Json Object?

//UserController

           public class UsersController : ApiController
                {
                    private LearnToLearnContext db = new LearnToLearnContext();
                    private BaseRepository<Users> _repository = null;

                    public UsersController()
                    {
                        this._repository = new BaseRepository<Users>();
                    }

                    // GET: api/Users
                    [ResponseType(typeof(Users))]
                    public IHttpActionResult GetUsers()
                    {
                        var user = _repository.GetAll();
                        var bindingModel = Mapper.Map<UsersBindingModels>(user);

                        return Ok(bindingModel);
                    }
            }


//UserModel

public class Users
    {
        [Key]
        public int Id { get; set; }
        [Required]
        public string Name { get; set; }
        [Unique]
        [Required]
        public string Email { get; set; }
        [Required]
        public string Password { get; set; }
        public bool IsTeacher { get; set; }

        public virtual List<Courses> Courses { get; set; }
    } 

//UserBindingModel
 public class UsersBindingModels
    {
        [Required]
        public string name { get; set; }
        [Unique]
        [Required]
        public string email { get; set; }
        [Required]
        public string password { get; set; }
        public bool isTeacher { get; set; }

        public virtual List<Courses> Courses { get; set; }
    }
Geya
  • 29
  • 6
  • What is the issues? Show us your JSON – Roman Marusyk Aug 18 '17 at 13:42
  • 1
    Possible duplicate of [How do I get ASP.NET Web API to return JSON instead of XML using Chrome?](https://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome) – Roman Marusyk Aug 18 '17 at 13:44

0 Answers0