如何基于另一个模型创建模型?
How do I create a model based on another model?
如何创建一个基于另一个模型的模型?
因为我只想选择所需的属性。
示例:
public class Test {
public string prop1 { get; set; }
public string prop2{ get; set; }
public decimal prop3 { get; set; }
}
我想要的样子:
public class TestViewModel {
public string prop1 { get; set; }
public decimal prop3 { get; set; }
}
我想这样做,因为我想制作视图,并且模型只包含必要的数据
恕我直言,您应该从头开始创建视图,没有任何继承。
模型和视图之间的唯一关系应该是视图的c-tor,它会得到一个模型类型的参数。
试试这个:
public class TestViewModel
{
public string prop1 { get; set; }
public decimal prop3 { get; set; }
}
public class Test: TestViewModel
{
public string prop2{ get; set; }
}
如何创建一个基于另一个模型的模型? 因为我只想选择所需的属性。
示例:
public class Test {
public string prop1 { get; set; }
public string prop2{ get; set; }
public decimal prop3 { get; set; }
}
我想要的样子:
public class TestViewModel {
public string prop1 { get; set; }
public decimal prop3 { get; set; }
}
我想这样做,因为我想制作视图,并且模型只包含必要的数据
恕我直言,您应该从头开始创建视图,没有任何继承。
模型和视图之间的唯一关系应该是视图的c-tor,它会得到一个模型类型的参数。
试试这个:
public class TestViewModel
{
public string prop1 { get; set; }
public decimal prop3 { get; set; }
}
public class Test: TestViewModel
{
public string prop2{ get; set; }
}