1
更新:我爲選擇列表項目添加了「綁定排除」。沒有爲此對象定義的無參數構造函數。 MVC4 Razor,已經在構造函數中精選了任何參數
現在,我越來越沒有IEnumerable類型的ViewDataItem有他們鍵等等等等......
如果我不能使用視圖模型的選擇列表,然後有什麼意義?
在POST操作中獲取此錯誤。我知道這已經被問過,但我沒有按照說明無濟於事。任何想法可能是錯的?不知道我是否應該包括觀點或不...
這裏是模型:
公共類推廣 {
[DisplayName("Number of Mailings")]
[Range(1, 100000,ErrorMessage="Please a positive number for Number of Mailings")]
public int mailings { get; set; }
[DisplayName("Number of Calls")]
public int pcalls { get; set; }
[DisplayName("Number of Emails")]
public int emails { get; set; }
[DisplayName("Number of Walkins")]
public int walkins { get; set; }
[DisplayName("Number of Faxes")]
public int faxes { get; set; }
public int osid { get; set; }
public int month { get; set; }
public int year { get; set; }
public Outreach()
{
}
}
}
這裏是視圖模型:
public class OutreachViewModel
{
[DisplayName("Outreach Specialist")]
public SelectList OutreachSpecialist{ get; set; }
public SelectList Year { get; set; }
public SelectList Month { get; set; }
public Outreach Out {get; set;}
}
這裏是控制器:
public ActionResult Create()
{
List<tblOutreachSpecialist> spec = repo.getAllSpecialists();
List<pYear> years=repo.getAllYears();
List<pMonth> months=repo.getAllMonths();
OutreachViewModel vw = new OutreachViewModel();
vw.Year = new SelectList(years, "id", "pYear1");
vw.Month = new SelectList(months, "id", "pMonth1");
vw.OutreachSpecialist = new SelectList(spec, "OSID", "LastName");
return View(vw);
}
[HttpPost]
public ActionResult Create(OutreachViewModel vm)
{
if (ModelState.IsValid)
{
repo.Add(vm.Out);
repo.Save();
}
return View(vm);
}
你在哪裏得到錯誤? – AaronLS 2013-04-08 23:42:48
在獲取或郵政? – AaronLS 2013-04-08 23:44:23
在帖子中獲取它。 – rsteckly 2013-04-08 23:45:50