lundi 2 mai 2016

Httpget Method using asp.net mvc in controller

Fetch data from database some error occur here (AdminPurpose con = i.a ) Message show Cannot implicitly converted type.Please see below for my code snippets:

 public JsonResult GetInfor()
    {

        List<AdminPurpose> all = new List<AdminPurpose>();;
        using (db_Hajj_UmrahEntities dc= new db_Hajj_UmrahEntities()) {

            var datas = (from  a in dc.Duas join b in dc.Purposes on a.PurposeId equals b.Id

               select new {
                   a,
                   b.PurPose1
        });


            if(datas != null) {


                foreach (var i in datas)
                {
                    AdminPurpose con =  i.a ;
                    con.PurPose1 = i.PurPose1;
                    all.Add(con);
                }
            }
        }

        return new JsonResult { Data = all, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    }
}

Model class one to many relation here it's using

[MetadataType(typeof(DuaMetaData))]
public partial class AdminPurpose
{
    public string PurPose1 { get; set; }
}

public class DuaMetaData
{

    public string Dua_Name { get; set; }
    public string Arabic_Word { get; set; }
    public string Translation_English { get; set; }
    public string Source { get; set; }

    [Display(Name = "Purpose")]
    public int PurposeId { get; set; }


}

Aucun commentaire:

Enregistrer un commentaire