I've been working on this project for a few days now, trying to get Cascading Dropdownlists to function properly. I'm having an issue where my State dropdownlist is not populating and no error message is displayed when the Ajax call fails. What could be wrong?
Here is a snippet of my code:
public class RegisterViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[Required]
[Display(Name ="User Name")]
public string UserName { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string Role { get; set; }
public List<SelectListItem> Countries { get; set; }
public List<SelectListItem> States { get; set; }
public void CascadingModel()
{
this.Countries = new List<SelectListItem>();
this.States = new List<SelectListItem>();
}
public int CountryId { get; set; }
public int StateId { get; set; }
}
And here is part of my controller code:
[AllowAnonymous]
[HttpGet]
public ActionResult Register()
{
RegisterViewModel model = new RegisterViewModel();
model.Countries = PopulateDropDown("SELECT Id, Name FROM Countries", "Name", "Id");
Country_Bind();
return View();
}
...
...
This is just a glimpse into what's going on with my cascading dropdownlists in the project.