Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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; }


C#
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; }
    }

C#
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

XML
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.
Posted

1 solution

Hello,

Maybe at the moment of doing the render of your page you are not using the List class..

I found this article and I think it can helps.

http://stackoverflow.com/questions/27378288/but-this-dictionary-requires-a-model-item-of-type-system-collections-generic-ie[^]


Best Regards!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900