Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting exception on dropdownlist line below is my code


@Html.LabelFor(m => m.cities, "DCityID", new { @class = "control-label col-md-2" })

@Html.DropDownListFor(m=> m.SelectedValue, new SelectList(Model.cities))/////error


//////////////viewmodel
C#
namespace edmxproject2.Models.ViewModels
{
    public class DoctorViewModel
    {
        public int DoctorID { get; set; }
        public string DName { get; set; }
        public int SelectedValue { get; set; }
        public virtual city city { get; set; }

        [DisplayName("City Name")]
        public virtual ICollection<city> cities { get; set; }
    }
}


//////Doctor class
XML
public partial class Doctor
   {
       public Doctor()
       {
           this.Doctor_specialization = new HashSet<Doctor_specialization>();
           this.patients = new HashSet<patient>();
           this.recepionists = new HashSet<recepionist>();
       }

       public int DoctorID { get; set; }
       public string DName { get; set; }
       public Nullable<bool> Dgender { get; set; }
       public Nullable<System.DateTime> DDOB { get; set; }
       public string Demail { get; set; }
       public string DhighSchool { get; set; }
       public string DMedicalCollege { get; set; }
       public string Daddress { get; set; }
       public string DwebLink { get; set; }
       public string Dexperience { get; set; }
       public Nullable<System.DateTime> DgraduationYear { get; set; }
       public Nullable<System.TimeSpan> DinTime { get; set; }
       public Nullable<System.TimeSpan> DoutTime { get; set; }
       [ForeignKey("city")]
       public Nullable<int> DCityID { get; set; }
       public Nullable<int> UserID { get; set; }

       public virtual city city { get; set; }
       public virtual ICollection<Doctor_specialization> Doctor_specialization { get; set; }
       public virtual user user { get; set; }
       public virtual ICollection<patient> patients { get; set; }
       public virtual ICollection<recepionist> recepionists { get; set; }
   }


/////CIty class
C#
public partial class city
    {
        public city()
        {
            this.Doctors = new HashSet<Doctor>();
            this.patients = new HashSet<patient>();
        }

        public int CityID { get; set; }
        public string cityname { get; set; }

        public virtual ICollection<Doctor> Doctors { get; set; }
        public virtual ICollection<patient> patients { get; set; }

    }
Posted
Comments
CHill60 16-Jul-14 8:27am    
What is the exception thrown?
safi rehman 16-Jul-14 8:37am    
Exception is solved but in dropdown list i am getting values like system.data.entity.dynamicproxies

1 solution

Try this

@Html.DropDownListFor(m=> m.SelectedValue, new SelectList(Model.cities,"SelectedValue","Cities"))


hope this works out.
else please check if the values are correctly getting binded to the viewmodel. Debug & check once

Please post reply /comment

Thanks
 
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