视图支持继承吗?
我基本上有一个模型,它由另一个模型组成,该模型是一个带有 2 个子类的基类。在我看来,我将如何使用它。显然,主模型将被传递到视图中;但是我如何将子模型转换为它的子类之一?请参阅以下示例来了解我的意思。在我看来,我会拥有 TransporationModel。假设我们正在从表单中收集该模型的数据,当前表单正在获取 Car 类型 Vehicle 的详细信息。提交表单后,我如何将汽车转换为其基本类型车辆?
public class TransaportationModel
{
public VehicleModle vehicle { get; set; }
...other fields
}
非常感谢, 詹姆斯
I basically have a model that consists of another model that is a base class with 2 sub classes. How would I use this in my view. Obviously the main model would be passed into the view; however how would I cast the the submodel to one of it's subsclassesclasses? Please see the following for an example of what I mean. In my view I would have the TransporationModel. Say we are collecting data for this model from a form, and the current form is getting details for a Car type Vehicle. On submitting the form how would I cast the Car to its base type Vehicle?
public class TransaportationModel
{
public VehicleModle vehicle { get; set; }
...other fields
}
Many thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自维基百科:
“模型管理应用程序域的行为和数据,响应有关其状态的信息请求(通常来自视图),并响应更改状态的指令(通常来自控制器)。在事件驱动的系统中,模型当信息发生变化时通知观察者(通常是视图),以便他们做出反应。”
这意味着管理数据的各个类本身并不是“模型”。所有这些类一起创建了模型。您应该更多地研究 MVC 模式和对象思维。
From Wikipedia:
"The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react."
This means the individual classes that manage your data aren't 'models' perse. It is all of these classes together that create the model. You should look more into MVC pattern and thinking in objects.