嵌套视图模型类的asp.net MVC [英] Nested ViewModel Classes in asp.net MVC

查看:272
本文介绍了嵌套视图模型类的asp.net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个MVC模型层域类。

I have four MVC model layer domain classes.

namespace MvcMobile.Models.BusinessObject
{
public class Speaker
{
    public int SpeakerID { get; set; }
    public string SpeakerName { get; set; }
}
public class Tag
{
    public int TagID { get; set; }
    public string TagName { get; set; }
}
public class Seminar
{
    public string Seminar_Code { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string Room { get; set; }        
}
public class Seminar_Detail
{
    public string Seminar_Code { get; set; }
    public int SpeakerID { get; set; }
    public int TagID { get; set; }
    public string DateAndTime { get; set; } 
}
}

我想用这些类进行CRUD操作。所以,我创建了两个 VeiwModel 类。

namespace MvcMobile.ViewModel
{
public class Seminar_Root_ViewModel
{
    public Seminar_Subsidiary_ViewModel Seminars { get; set; }
    public List<Speaker> Speakers { get; set; }
    public List<Tag> Tags { get; set; }
}
public class Seminar_Subsidiary_ViewModel
{
    public Seminar Seminar { get; set; }
    public List<Seminar_Detail> Seminar_Detail { get; set; }
}
}

有关控制器层,我认为我会用 Seminar_Root_ViewModel 来使整个CRUD操作流程。

For Controller layer, I consider that I will use Seminar_Root_ViewModel to make the whole CRUD operation processes.

我想问的是,这是正确的方式还是正确的方法是什么?
如果你有更优雅的方式,使模型层和视图模型层,请让我的建议。

What I would like to ask is that Is this proper way or correct way?
If you have more elegant way to make model layer and ViewModel layer, Please let me get suggestion.

每一个建议将是AP preciated。

Every suggestion will be appreciated.

让我们假设我做主从表单设计。

Let's assume that I make master-Detail form design.

扬声器和标签只是查找弥补的DropDownList或表格这样的一些控制。
研讨会是主数据和 Seminar_Detail 将项目网格数据。
因此,对于这种情况下,所有这些类都需要对这一计划。

Speaker and Tag are just look-up tables for dropdownlist or some controls like that.
Seminar is Master Data and Seminar_Detail will be Item Grid Data.
So As for this scenario, all of this classes are needed for this program.

请让我知道,如果我的想法是错误的。

Please let me know if my thinking is wrong.

推荐答案

我可以看到的唯一的事情是,如果你不打算再使用 Seminar_Subsidiary_ViewModel 视图模型你可以跳过它。

The only thing I can see is if you are not going to re-use your Seminar_Subsidiary_ViewModel view model you could skip it.

如果您将需要这两个属性研讨会 Seminar_Detail 上的另一个观点或Ajax调用,这是完全精致有那种分离的。

If you are going to need those two properties Seminar and Seminar_Detail on another view or ajax call, it's perfectly fine to have that kind of separation.

我个人不是_类名的超级粉丝,但什么都没有做的问题。

Personally I'm not a huge fan of _ on class name, but that have nothing to do with the question.

这篇关于嵌套视图模型类的asp.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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