Below is my MVC View model
public class UserViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int UserID { get; set; }
public IEnumerable<Role> LstRole { get; set; }
}
I need to convert this to JSON in controller action method which emits JSON to angularjs
function
Below is my action method in controller
public string GetAllUsers()
{
objUserView.LstRole = objUserManager.GetAllRoles();
objUserView.FirstName = "Test";
objUserView.LastName = "Test 1";
objUserView.UserID = 1;
return JsonConvert.SerializeObject(objUserView.LstRole, Formatting.None, new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
TypeNameHandling = TypeNameHandling.All
});
}
When I run this action method it gives below error
Self referencing loop detected for property 'Role' with type 'System.Data.Entity.DynamicProxies.Role_EE4037A57E80F8AE5D8E070E7325B72D7AE3916C26C19F53CB6F5084B2181234'. Path '$values
enter code here
[1].UserMasters.$values[0]'.
Please assist