Good day ! I am very new to ASP.NET and tried to research multiple tutorials and would much appreciate this community's feedback.
I am trying to build a cascading dropdownlist from another model. In the course I created a CombinedModel
Model-view
//Combined model
namespace WebApplication2.Models
{
public class CombinedModel
{
public RegisterViewModel RegisterViewModel { get; set; }
public DistrictModel Districtmodel { get; set; }
}
}
//Model 1
public class RegisterViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
public string ConfirmPassword { get; set; }
public virtual List<DistrictModel> DistrictName { get; set; }
//Model 2
namespace WebApplication2.Models
{
public class DistrictModel
{
public int DistrictID { get; set; }
public string DistrictName { get; set; }
}
}
Controller-View
public ActionResult Register()
{
ViewBag.DistrictNameList = new SelectList(db.DistrictModel, "DistrictName", "DistrictName");
return View();
}
View
model WebApplication2.Models.CombinedModel
using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
<div class="col-md-10">
Html.DropDownListFor(m => m.RegisterViewModel.DistrictName, ViewBag.DistrictNameList, new { @class = "form-control" } )
</div>
And it doesn't seem to work... I tried changing it to Enum and its still wouldn't comply. I would appreciate your feedback on this !