ASP.Net MVC 4
ドロップダウンリストに国のリスト (DB の Country テーブルのデータ) を入力しようとしています。次のエラーが表示されます。
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 は初めてで、そのエラーがわかりません。私が感じているのは、Index メソッドが返すものは、View で使用しているモデルと一致しないということです。
モデル::
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>
どこが間違っていますか?