1

我有以下课程:

   public class City {
      public string key1 {get; set; }
      public string key2 { get; set; }
      public string col1 { get; set; }
      public string col2 { get; set; }
      public int newplusnew2 { get; set; }
   }

一个视图模型:

   public class CityViewModel {
      public City city { get; set; }
      public int new1 { get; set; }
      public int new1 { get; set; }
   }

一种行为:

 public JsonResult JsonCreate(CityViewModel viewModel)
        {

 //  Validation checks go here

            var model = new City ();
            ???

   }

有人能告诉我从视图模型中填充四个字符串列和 int 列的最佳方法吗?我只是想知道是否有一些推荐的方法来做到这一点。

4

1 回答 1

1

如果我理解正确,您CityViewModel从回发中得到回复,并且您需要City离开......但据我所知,CityViewModel已经包含一个City对象,所以您可以这样做:

public JsonResult JsonCreate(CityViewModel viewModel)
{
    //  Validation checks go here
    var model = viewModel.city;
}
于 2012-05-06T09:38:02.933 回答