코드를 설정할 수 없습니다. var GetAllDetails
바로 뒤에 중단 점을 넣었으므로 ViewData["GetAllDetails"]
이 제대로 채워 졌는지 확인할 수 있습니다. 타입 캐스팅 할 모델에는 ViewData.
과 같은 값의 이름과 타입이 있습니다. 어쨌든 GotAllDetails
은 null
입니다. 페이지가 칠 때 내 foreach
그것은 나에게, 객체 참조
예외 정보를 전달합니다 : System.NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.
요청에 따라 더 많은 코드를 공유 하겠지만 먼저 명백한 오류가 있는지 알려주십시오.
편집 : 요청에 따라 여기 [ "GetAllDetails"]
ViewData["GetAllDetails"] = getAllDetails.OrderBy(q => PadString(q.TaskDescription, ".")).ToList();
그리고 LINQ 쿼리
var getAllDetails =
(from m in _db.MyStandards.AsEnumerable()
join t in _db.Tasks on m.TaskId equals t.TaskId
join p in _db.Products on t.ProductId equals p.ProductId
join ce in _db.CompetencyElements on p.CompetencyElementId equals ce.CompetencyElementId
join comp in _db.Competencies on ce.CompetencyId equals comp.CompetencyId
join fu in _db.FunctionalUnitOfCompetences on comp.FunUnitOfCompetenceId equals fu.FunUnitOfCompetenceId
join c in _db.Careers on fu.CareerId equals c.CareerId
join rx in _db.RubricRefs on m.RubricStandardId equals rx.Id
where (t.TaskId == m.TaskId && m.Email == getUserById && p.ProductId == proId)
group new { t.TaskDescription, m.RubricStandardId, m.Comments }
by new
{
c.CareerDescription,
fu.FunUnitOfCompetenceDesc,
comp.CompetencyDescription,
ce.CompetencyElementdesc,
p.ProductDescription,
t.TaskDescription,
m.RubricStandardId,
m.Comments,
m.StandardId,
m.TaskId,
m.ActiveInd,
rx.RubricHexColor,
rx.RubricSymbol
} into g
select new
{
ActiveInd = g.Key.ActiveInd,
CareerDescription = g.Key.CareerDescription,
Comments = g.Key.Comments,
CompetencyDescription = g.Key.CompetencyDescription,
CompetencyElementdesc = g.Key.CompetencyElementdesc,
FunUnitOfCompetenceDesc = g.Key.FunUnitOfCompetenceDesc,
ProductDescription = g.Key.ProductDescription,
StandardId = g.Key.StandardId,
RubricHexColor = g.Key.RubricHexColor,
RubricStandardId = g.Key.RubricStandardId,
RubricSymbol = g.Key.RubricSymbol,
TaskDescription = g.Key.TaskDescription,
TaskId = g.Key.TaskId,
});
그리고 모델
public class DetailViewsModel
{
public string ActiveInd { get; set; }
public string CareerDescription {get;set;}
public string Comments {get;set;}
public string CompetencyDescription {get;set;}
public string CompetencyElementdesc {get;set;}
public string FunUnitOfCompetenceDesc {get;set;}
public string ProductDescription {get;set;}
public int StandardId {get;set;}
public string RubricHexColor {get;set;}
public int RubricStandardId {get;set;}
public string RubricSymbol {get;set;}
public string TaskDescription {get;set;}
public int TaskId {get;set;}
}
"적절하게 채워짐"은 ViewData [ "GetAllDetails"]'가 실제로 List을 반환한다는 것을 의미합니까? 반환 된 객체가 다른 유형 인 경우 'as'연산자는 'null'을 반환합니다. –
내가 아는 한, 그렇습니다. ViewData는 LINQ 쿼리에서오고 있으며, 내가 typecasting하고있는 모델이 상기 쿼리의 출력과 동일한 값을 가지고 있는지 확인했습니다. – UIDAlexD
동일한 속성을 가진 경우 내 질문이 아니 었습니다. 디버깅했다고해서 다시 디버깅하고 실제 유형을 결정할 수 있습니다. 내가 말했듯이, 그것이 올바른 타입이 아니라면,'GotAllDetails'는 null이 될 것입니다. 그렇다면 어떤 종류의 전환이 필요할 것입니다. –