varun sharma

varun sharma

  • 1.9k
  • 150
  • 1.8k

Getting error while sending data from controller to view.

Jan 12 2020 12:59 AM
Column cndID is present in the model class and I get the data in the "result riew" but while sending data from controller to view is not working, getting below error but while using return View(db.cndPersonalDetails.ToList()); its working fine.
 
Kindly suggest how to resolve this issue.
 
Message "error CS1061: 'IQueryable<cndPersonalDetail>' does not contain a definition for 'cndID' and no extension method 'cndID' accepting a first argument of type 'IQueryable<cndPersonalDetail>' could be found (are you missing a using directive or an assembly reference?)" string
 
var userid = Session["UserName"].ToString();
var id = db.Registrations.Where(m => m.userID == userid).Select(m => m.id).FirstOrDefault();
var result = db.cndPersonalDetails.Join(db.registrationDetails,
a => a.id, b => b.createdFor, (a, b) => new { a, b }).ToList().
Join(db.Registrations, r => r.b.createdBy, reg => reg.id, (r, reg) => new { r, reg }).ToList()
.Where(m => m.r.b.createdBy == id).Select(m => new { m.r.a.cndID, m.r.a.createdBy, m.r.a.emailID, m.r.a.experienceMonth, m.r.a.experienceYear, m.r.a.isActive, m.r.a.Name, m.r.a.Number, m.r.a.Resume});
return View(result.ToList());
 
View
 
@model IQueryable<hrProject.Models.cndPersonalDetail>
namespace hrProject.Models
{
using System;
using System.Collections.Generic;
public partial class cndPersonalDetail
{
public int id { get; set; }
public string cndID { get; set; }
public string Name { get; set; }
public int Number { get; set; }
public string emailID { get; set; }
public int experienceYear { get; set; }
public int experienceMonth { get; set; }
public byte[] Resume { get; set; }
public string createdBy { get; set; }
public bool isActive { get; set; }
}
}
 
Below is the result view
 
+ [0] { cndID = "2", createdBy = "tarun@gmail.com", emailID = "Varun@Varun", experienceMonth = 5, experienceYear = 4, isActive = true, Name = "Varun", Number = 99538, Resume = null } <Anonymous Type>
+ [1] { cndID = "3", createdBy = "tarun@gmail.com", emailID = "varun", experienceMonth = 3, experienceYear = 5, isActive = true, Name = "Varun1", Number = 255, Resume = null } <Anonymous Type>
+ [2] { cndID = "4", createdBy = "tarun@gmail.com", emailID = "gjyg", experienceMonth = 85, experienceYear = 87, isActive = true, Name = "Varun2", Number = 21516, Resume = null } <Anonymous Type>

Answers (1)