【发布时间】:2011-08-17 18:32:38
【问题描述】:
这是我的代码:
[HttpGet]
public ActionResult Register()
{
RegisterViewModel model = new RegisterViewModel();
using (CityRepository city = new CityRepository())
{
model.SelectCityList = new SelectList(city.FindAllCities().ToList(), "CityID", "CityName");
}
using (CountryRepository country = new CountryRepository())
{
model.SelectCountryList = new SelectList(country.FindAllCountries().ToList(), "CountryID", "CountryName");
}
return View(model);
}
[HttpPost]
public ActionResult Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
//Actually register the user here.
RedirectToAction("Index", "Home");
}
//Something went wrong, redisplay the form for correction.
return View(model);
}
这是最好的方法还是有另一种更好的测试方法?请记住,我的数据库表/字段名称与我在模型中声明的完全不同。我必须从 ViewModel 中抓取值并将它们放入实体框架生成的类中以保存信息。
这里有什么对你大喊大叫的错误吗?
【问题讨论】:
标签: view controller asp.net-mvc-3