2 つの NameSpaces を含めたいのは、Razor View に 2 つの ViewModel を意味しAddViewModel
ますupdateVIewModel
。
現在、次のような1つのビューモデルを使用しています:
/* NameSpace Name */
@model Web.Models.SettingViewModel;
追加したい:
@model Web.Models.UpdateSettingViewModel
これを行う方法 ??
2 つの NameSpaces を含めたいのは、Razor View に 2 つの ViewModel を意味しAddViewModel
ますupdateVIewModel
。
現在、次のような1つのビューモデルを使用しています:
/* NameSpace Name */
@model Web.Models.SettingViewModel;
追加したい:
@model Web.Models.UpdateSettingViewModel
これを行う方法 ??
タプルview
に渡すことができます
//create the instances
SettingViewModel svm = new SettingViewModel();
UpdateSettingViewModel usv = new UpdateSettingViewModel();
//create the Tuple
var tpl = new Tuple<SettingViewModel, UpdateSettingViewModel>(svm,usv);
//pass the Tuple to the view
return View(tpl);
//get the values
var a = tpl.Item1;
var b = tpl.Item2;
またはダイナミック
//Create a dynamic object
dynamic dn = new { SettingViewModel = svm, UpdateSettingViewModel = usv };
//pass the dynamic to the view
return View(dn);
//get the values in the view
var dn1 = dn.SettingViewModel;
var dn2 = dn.UpdateSettingViewModel;
これら 2 つの viemodel をプロパティとして持つビューモデルを作成する必要があります。現在、2 つ以上のビューモデルを Razor ビューに渡すことはできません。