前の Dropdownlisfor 選択の結果を受け取るために、空の Dropdownlistfor を作成したいと思います。
実際のビュー:
<div id="makes">
@Html.DropDownListFor(m => m.Make_Id, Model.MakeList, HeelpResources.DropdownlistMakeFirstRecord)
</div>
<div id="models">
@Html.DropDownListFor(m => m.Model_Id, Model.ModelList, HeelpResources.DropdownlistModelFirstRecord)
</div>
実際のコントローラー (動作させるには、空の SelectedList を作成する必要がありましたが、これを行う必要があるのは奇妙に思えます):
public virtual ActionResult Create()
{
// Build the Dropdownlist for the Makes
var makesDto = _makeService.ListAllMakes();
var makesViewModel = Mapper.Map<IList<MakeDto>, IList<MakeViewModel>>(makesDto);
// Build the Dropdownlist for the Models
var makeId = -1;
var modelsDto = _modelService.ListModelByMake(makeId);
var modelsViewModel = Mapper.Map<IList<ModelDto>, IList<ModelViewModel>>(modelsDto);
// Build the ViewModel to return to the View
CreateAdViewModel viewModel = new CreateAdViewModel();
viewModel.MakeList = new SelectList(makesViewModel, "ID", "Name");
viewModel.ModelList = new SelectList(modelsViewModel, "ID", "Name");
return View(viewModel);
}
このようなものを構築する方法はありますか: @Html.DropDownListFor(m => m.Model_Id, null)
// Build the Dropdownlist for the Models? をコントローラーから削除しますか?
ありがとう