您如何命名ViewModel类? [英] How do you name your ViewModel classes?

查看:173
本文介绍了您如何命名ViewModel类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种命名约定适用于ViewModel类?

What kind of naming convention is appropriate for ViewModel classes?

示例:对于HomeController,索引视图? HomeIndexViewModel似乎不正确.

Example: for HomeController, Index view? HomeIndexViewModel doesn't seem right.

推荐答案

EmployeesViewData.

EmployeesViewData.

这就是我所使用的,也是我在示例应用程序中所看到的.

That's what I use and what I've seen in sample applications as well.

关于您添加的示例:恕我直言,类的名称应指定其包含的数据类型. ".... IndexViewData"是毫无意义的.该页面上到底显示了什么?尝试用1或2个字来概括它,并在其后添加"ViewData".

About your added example: Imho the name of the class should specify what kind of data it contains. "....IndexViewData" is rather meaningless. What exactly is displayed on that page? Try to summarize it in 1 or 2 word(s) and add 'ViewData' behind it.

否则,只需使用控制器的名称并删除索引"即可. HomeViewData对我来说听起来不错.

Or else just take the name of the controller and drop the "index". HomeViewData sounds fine to me.

这篇关于您如何命名ViewModel类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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