次のようなモデルがあるとします。
public class LoginModel
{
pulbic List<string> UserNames {get; set; }
public string SelectedUserName {get; set; }
public string Password {get; set; }
}
また、次のようないくつかのアクション メソッドを備えたコントローラーもあります。
public ActionResult Login()
{
LoginModel model = null;
model = new LoginModel();
// Code to populate the UserNames property of the LoginModel instance (model)...
return View(model);
}
[HttpPost()]
public ActionResult Login(LoginModel model)
{
if (ModelState.IsValid == true)
{
return RedirectToAction("SomeOtherAction")
}
else
{
return View(model);
}
}
View メソッドに渡す前に、モデル オブジェクトの UserNames プロパティを再設定する必要があります。これは確かにできることですが、少し汚れているように感じます。それは私を質問に導きます。これを処理するより良い方法はありますか?