在剃刀视图中包含2个名称空间?

时间:2013-06-03 05:21:39

标签: asp.net-mvc razor

我想包括2个N​​ameSpaces意味着2个ViewModel到我的Razor View AddViewModelupdateVIewModel

目前我正在使用One View模型,如:

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

我想补充一下:

@model Web.Models.UpdateSettingViewModel 

怎么做?

2 个答案:

答案 0 :(得分:1)

您可以转到view一个Tuple

  //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;

dynamic

  //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;

答案 1 :(得分:0)

您应该创建一个具有这两个viemodel作为其属性的viewmodel。目前,您无法将两个或更多视图模型传递给剃刀视图。

相关问题