public ContentResult AddCategory([Bind(Exclude = "id")] Categories category) { string json; if (TryValidateModel(category)) { var id = _catRepository.CreateCategory(category); json = JsonConvert.SerializeObject(new { id = id, success = true, message = "Category added successfully." }); } else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to add the category." }); } return(Content(json, "application/json")); }