使用ViewModel值初始化模型 [英] Initializing model with ViewModel values

查看:103
本文介绍了使用ViewModel值初始化模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用ViewModel中的Example模型中的值初始化一个新的Example模型.

I want to initialize a new Example model with values from an Example model within the ViewModel.

var example = new Example { ExampleViewModel.Example};

以上返回错误:

无法使用集合初始化程序初始化类型"ManagementOfChange.Models.ChangeRequest",因为它未实现"System.Collections.IEnumerable"

Cannot initialize type 'ManagementOfChange.Models.ChangeRequest' with a collection initializer because it does not implement 'System.Collections.IEnumerable'

这是否意味着我必须分别初始化每个值?例如:

Does this mean I have to initialize every value individually? e.g:

var example = new Example 
    { 
        value1 = ExampleViewModel.value1, 
        value2 = ExampleViewModel.value2 
    };

或者这只是我的语法问题吗?

Or is this just a problem with my syntax?

推荐答案

我认为您的情况与此相同:

I think in your case it is the same to do this:

var example = ExampleViewModel.Example;

这篇关于使用ViewModel值初始化模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆