ASP.Net MVC 4모델 항목 유형 인 'System.Collections.Generic.List`1는 [선택 System.Int32]'
나는이 나라의 목록을 채우기 위해 노력하고 있어요 (데이터 DB의 국가 테이블) 드롭 다운 목록에 있습니다.
The model item passed into the dictionary is of type
System.Collections.Generic.List`1[System.Int32]', but this dictionary requires a model item of type 'BIReport.Models.Country'.
내가 ASP.Net MVC 새로운 오전과 내가 그 오류를 이해하지 않는다 : 나는 다음과 같은 오류가 발생합니다. 인덱스 메소드가 반환하는 것이 뷰에서 사용중인 모델과 일치하지 않는다고 생각합니다.
모델 ::
namespace BIReport.Models
{
public partial class Country
{
public int Country_ID { get; set; }
public string Country_Name { get; set; }
public string Country_Code { get; set; }
public string Country_Acronym { get; set; }
}
}
컨트롤러 ::
public class HomeController : Controller
{
private CorpCostEntities _context;
public HomeController()
{
_context = new CorpCostEntities();
}
//
// GET: /Home/
public ActionResult Index()
{
var countries = _context.Countries.Select(arg => arg.Country_ID).ToList();
ViewData["Country_ID"] = new SelectList(countries);
return View(countries);
}
}
보기 :: 내가 잘못 가고
@model BIReport.Models.Country
<label>
Country @Html.DropDownListFor(model => model.Country_ID, ViewData["Country_ID"] as SelectList)
</label>
?
나는 국가 테이블이 있는데, 여기에 Country_Name이라는 다른 열이 많이 있습니다. 그래서 저는 국가를 모델로 삼았습니다. 그것이 틀린 지 알지 못합니다. Btw, 당신의 경우에 어떻게 View 코드가 보이겠습니까? 이걸 물어서 미안해. – shaz
그래서 당신의 견해는 여러 국가로 구성된 테이블로되어 있습니까? –
MVC 컨텍스트에서 어떻게 말할 지 모르겠지만 내 인덱스 페이지에 국가 목록과 함께 드롭 다운 목록을 표시하려고합니다. 그래서 저는 Country라는 테이블을 가지고 있습니다 - – shaz