私のアクションInsertPerson
では、次のプロパティを持つモデルを使用します。
pulbic class InsertPerson
{
[Required]
public string Name{get;set;}
}
リポジトリに渡される DTO モデルがあります。
public class PersonDto
{
public int Id{get;set;}
public string Name{get;set;}
public string LastName{get;set;}
}
私の行動:
[HttpPost]
public ActionResult Create(InsertPerson insertPerson)
{
if(ModelState.IsValid){
var personDto = new PersonDto();
UpdateModel(personDto)
//UpdateModel(personDto, "insertPerson") I've tried this too
}
}
なぜ機能しないのですか(UpdateModelの後、すべてのプロパティはまだnullです)?
私のpersonDto
使用を更新する方法はありますUpdateModel
か?
AutoMapper については知っていますが、コントローラーで使用するのはつまらないと思います。
私の見解:
@model Help_Desk.ViewModel.InsertPersonViewModel
@using (Html.BeginForm())
{
@Html.TextBoxFor(m => m.InsertPerson.Name)
<button type="submit">Save</button>
}
と私のビューモデル:
public class InsertPersonViewModel
{
public InsertPerson InsertPerson{ get; set; }
}