I am building a registeration form, i am having problem in which class should i bind my index view to i am having three classes Districts, Tehsil, Subtehsil, which basically implement the cascading dropdownlist in the same order.
public partial class District
{
public District()
{
this.tbTehsils = new HashSet<Tehsil>();
}
public int DistrictId { get; set; }
public string DistrictName { get; set; }
public virtual ICollection<Tehsil> tbTehsils { get; set; }
public partial class SubTehsil
{
public int SubTehsilId { get; set; }
public string SubTehsilName { get; set; }
public Nullable<int> TehsilId { get; set; }
public virtual Tehsil tbTehsil { get; set; }
}
public partial class Tehsil
{
public Tehsil()
{
this.tbSubTehsils = new HashSet<SubTehsil>();
}
public int TehsilId { get; set; }
public string TehsilName { get; set; }
public int DistrictId { get; set; }
public virtual District tbDistrict { get; set; }
public virtual ICollection<SubTehsil> tbSubTehsils { get; set; }
here is my fields in registeration form
public partial class ApplicationFormFarmersSolarPower
{
public int Id { get; set; }
public Nullable<long> UniqueId { get; set; }
public string District { get; set; }
public string Tehsil { get; set; }
public string SubTehsil { get; set; }
public string Village { get; set; }
public string NameOfApplicant { get; set; }
public string NameOfLandOwners { get; set; }
public string ResidentAddress { get; set; }
public Nullable<long> PinCode { get; set; }
public Nullable<long> MobileNumber { get; set; }
public string EmailId { get; set; }
public string NearestStation { get; set; }
public string DistanceOfSubstation { get; set; }
public string AreaOfLand { get; set; }
public string ProposedPlantCapacity { get; set; }
}
i also have a DBContext class genetrated automatically by EF which is basically to retrieve data from the database.
Now when i create strongly typed view against DBContext it gives an error
Quote:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[FarmerRegisterFormAndPrint.Models.District]', but this dictionary requires a model item of type 'FarmerRegisterFormAndPrint.Models.FarmerDBContext'.
basically i am failing to understand which class i should bind my view
I have used this code in index ActionResult
Quote:
FarmerDBContext db = new FarmerDBContext();
db.Districts.ToList();
i read this article but i am failing to understand what the ProductCatalogclass have.
Simple Implementation of MVC Cascading Ajax Drop Down on this same website
My main motive is to generate cascading DDL from database in my registeration form.