저는 book에서 ASP.NET MVC를 배우는 초보자입니다 .IntC를 구현하기 위해 NInject를 사용하고 있습니다. 나는보기에서 두 개의 다른 모델의 데이터 표시
테이블 이름 아래와 같이 작업 및 위치에 대한 데이터 모델을 만들었습니다 - JobDetails
JobId<PK>
LocationId<FK>
JobName
테이블 이름 - 위치
LocationId<PK>
LocationName
나는 위치와 JobDetails에 대한 실체를 만들었을 이하는
직업 세부
public class JobDetails
{
[Key]
public int JOBID { get; set; }
public int LocationID { get; set; }
public string JOBNAME { get; set; }
}
public class Location
{
[Key]
public int LocationID{ get; set; }
public string LocationName { get; set; }
}
이 또한 내가 작업 및 위치에 대한
public interface IJobDetails
{
IEnumerable<JobDetails> jobDetailsInterface { get; }
}
public interface ILocation
{
IEnumerable<Location> locationInterface { get; }
}
public class EFLocationRepository : ILocation
{
public EFDbContext context = new EFDbContext();
public IEnumerable<Location> locationInterface
{
get { return context.Location; }
}
}
public class EFJobRepository : IJobDetails
{
public EFDbContext context = new EFDbContext();
public IEnumerable<JobDetails> jobDetailsInterface
{
get { return context.JobDetails; }
}
}
내 모델 클래스를 아래와 같이 작업 정보 및 위치에 대한 내 추상 및 상황에 맞는 클래스가 위치과 같습니다 이하
public class JobListViewModel
{
public IEnumerable<JobDetails> jobDetails { get; set; }
}
public class LocationListViewModel
{
public IEnumerable<Location> Location { get; set; }
}
내 JobDetail 컨트롤러에서 위치 ID 대신 위치 이름을 표시하려고합니다. 내 JobDetail의 컨트롤러는 다음과 같다
public class JobController : Controller
{
public IJobDetails repository;
public JobController(IJobDetails job)
{
repository = job;
}
public ViewResult List()
{
return View(repository.jobDetailsInterface);
}
}
어떻게 내 작업보기에서 위치 이름 대신 위치 ID를 표시합니다?
N.B- 저는 Adam Freeman의 책에서 MVC를 배우고 새로운 것을 만들어 내려고합니다. 내가 한 일이 맞는지 아닌지 알려주세요.
EntityFramework를 사용하고 있습니까? 그렇다면'repository.jobDetailsInterface.Location.LocationName'과 같은 작업 저장소를 통해 LocationName에 접근 할 수 있어야합니다. – sleeyuen
Entity Framework를 사용하고 있습니다.하지만 jobDetailsInterface를 통해 locationName에 액세스 할 수 없습니다. – BSB