0

2 つの NameSpaces を含めたいのは、Razor View に 2 つの ViewModel を意味しAddViewModelますupdateVIewModel

現在、次のような1つのビューモデルを使用しています:

/* NameSpace Name */
@model Web.Models.SettingViewModel;

追加したい:

@model Web.Models.UpdateSettingViewModel 

これを行う方法 ??

4

2 に答える 2

1

タプル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;
于 2013-06-03T05:57:22.037 に答える
0

これら 2 つの viemodel をプロパティとして持つビューモデルを作成する必要があります。現在、2 つ以上のビューモデルを Razor ビューに渡すことはできません。

于 2013-06-03T05:31:46.947 に答える