내 html로 액션 링크는 내가 예를 들어 .. 를 세부 사항을 볼 수있는보기로 나를 취 ... http://localhost:1985/Materials/Details/4
를하지만 오류를 보여줍니다이 모델 오류는 asp.net mvc에서 무엇이라고 말합니까?
The model item passed into the dictionary is of type
'System.Data.Linq.DataQuery`1[CrMVC.Models.ConstructionRepository+Materials]'
but this dictionary requires a model item of type
'CrMVC.Models.ConstructionRepository+Materials'.
그리고 내 모델이다
public IQueryable<Materials> GetMaterial(int id)
{
return from m in db.Materials
join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id
where m.Mat_id == id
select new Materials()
{
Id = Convert.ToInt64(m.Mat_id),
Mat_Name = m.Mat_Name,
Mes_Name = Mt.Name,
};
}
public class Materials
{
private Int64 id;
public string mat_Name;
public string mes_Name;
public Int64 Id
{
get
{
return id;
}
set
{
id = value;
}
}
public string Mat_Name
{
get
{
return mat_Name;
}
set
{
mat_Name = value;
}
}
public string Mes_Name
{
get
{
return mes_Name;
}
set
{
mes_Name = value;
}
}
}
}
및 제 컨트롤러 방법 ...
public ActionResult Details(int id)
{
var material = consRepository.GetMaterial(id).AsQueryable();
return View("Details", material);
}
어떤 제안이 있습니까?
.net 2 (또는 그 이상)로 작업하고 계십니까? 그렇지 않으면 자동 속성을 사용하여 코드 양을 줄이고 더 읽기 쉽게 만들 수 있습니다. 예를 들어 다음을 참조하십시오. http://weblogs.asp.net/dwahlin/archive/2007/12/04/c-3-0-features-automatic-properties.aspx – M4N