首页 \ 问答 \ ASP.NET MVC - 查看模型模式(ASP.NET MVC - View Model pattern)

ASP.NET MVC - 查看模型模式(ASP.NET MVC - View Model pattern)

我现在只使用MVC框架(ASP.NET MVC2 / 3 / Razor)几个月了,我真的很享受它,但是我很难找到View Models的标准。 在我的项目中,我有一个Models文件夹(包含我的数据模型 - Linq DBML,Repository [ies],扩展方法)和Models / ViewModels文件夹。 我的视图模型通常是可重用的类,通常只包含LINQ对象的简单get / set属性或我需要为特定视图访问的对象集合。

现在我遇到的问题是弄清楚何时创建一个视图模型。 我的目标是尽可能经常使用LINQ对象作为视图模型,尤其是当它是一个Edit动作时。 我的问题是,如果我有其他数据,我可能只想用于显示目的? 我不喜欢使用ViewData / ViewBag集合,因为访问这些集合的成员需要了解集合项的密钥(设计人员/前端人员不容易“猜测”)。 我也不喜欢为每个View创建一个ViewModel的想法,因为它似乎是不必要的混乱代码。

例如,假设我有一个Employee的数据模型,我想显示一些与该员工无关的信息 - 例如,站点统计信息,动态菜单以及您可能想到的可能来自数据库的任何其他信息。 我应该通过什么模型/ Employee / Edit操作? 带有一堆ViewData []的Employee对象,还是自定义的EmployeeView?

有金标准吗? 我错过了什么? 你在做什么不同我应该研究一下? 提前致谢!


I have only been working with the MVC framework (ASP.NET MVC2/3/Razor) for a few months now and I am really enjoying it, however I am having a hard time figuring out a standard for View Models. In my projects, I have a Models folder (Contains my data models - Linq DBML, Repository[ies], Extension methods) and a Models/ViewModels folder. My view models are usually reusable classes which usually just contain simple get/set properties for the LINQ objects or collections of objects I need to access for a particular view.

Now the problem I am having is figuring out when to create a view model. My goal is to use the LINQ object as the view model as often as possible, especially when it is an Edit action. My problem is what if I have other bits of data that I might want to use for display purposes only? I don't like to use the ViewData/ViewBag collections, as accessing members of these requires knowledge of the collection item's key (not easy for a designer/front-end guy to "guess"). I also don't like the idea of creating a ViewModel for each View, as it seems like unnecessarily messy code.

For example, imagine I have a data model for an Employee, and I want to display some information unrelated to that employee - say, site statistics, dynamic menus, and whatever else you can think of that might come from the database. What model should I pass the /Employee/Edit action? The Employee object with a bunch of ViewData[] for the rest, or a custom EmployeeView?

Is there a gold standard? What am I missing? What are you doing different that I should look into? Thanks in advance!


原文:https://stackoverflow.com/questions/6077913
更新时间:2021-10-24 07:10

最满意答案

关于docker docker/hub-feedback lfs没有任何内容。

docker/docs.docker.com / notarydocker/docs.docker.comdocker/docs.docker.com docker/distribution也没有任何内容

Docker Hub自动构建 “允许您使用Docker Hub的构建集群自动从包含Dockerfile的GitHub或Bitbucket存储库创建映像”。

由于Git LFS只是GitHub上的官方版本,因此在过去的14天里 ,repos 只是正式的 ,并且正在为BitBucket工作 (来自他们最初的Git LOB计划),似乎可以肯定地说自动构建还不支持LFS。


2016年6月更新, Andy Li 在以下评论中报道:

现在,docker / hub-feedback中存在功能请求问题:

问题500:“ 添加对Git LFS的支持
它需要您的支持(或您的Pull-Requests)


There is nothing regarding lfs in docker/hub-feedback.

Nor is there anything in docker/notary or docker/docs.docker.com, or docker/distribution

The Docker Hub Automatic build "allow[s] you to use Docker Hub’s build clusters to automatically create images from a GitHub or Bitbucket repository containing a Dockerfile".

Since Git LFS is only official on GitHub repos is only official for the last 14 days, and being worked on for BitBucket (coming from their original Git LOB initiative), it seems safe to say LFS isn't yet supported by an Automatic build.


Update June 2016, Andy Li reports in the comments below:

There is now a feature request issue in docker/hub-feedback:

Issue 500: "Add support for Git LFS".
It needs your support (or your Pull-Requests)

相关问答

更多
  • 这是i386上的32位寻址问题,Git和git-lfs根本无法寻址大于4 GB的文件。 32位无符号整数的最大值是4,294,967,295 ,约为4GB。 我们可以在git-compat-util.h看到这个错误在Git源代码中git-compat-util.h : 744 static inline size_t xsize_t(off_t len) 745 { 746 if (len > (size_t) len) 747 die("Cannot handle files th ...
  • 好的,所以这个问题已经解决了,最后GitHub在本地工作多天后再次变绿了:) 问题是git-lfs(Git Large File Storage),并且因为它阻止了用于上传的大文件,所以还显示了第二个错误。 1)我使用以下命令从系统中卸载了git-lfs,因为显然还没有卸载程序。 $ git config --global --unset filter.lfs.required $ git config --global --unset filter.lfs.smudge $ git config -- ...
  • 没有确切的阈值来定义什么是大文件。 这取决于用户。 要查看是否需要使用Git LFS存储某些文件,您需要了解git如何工作。 Git和其他源代码控制工具(perforce,svn)之间最根本的区别在于,Git在每次提交时都存储了存储库的完整快照。 因此,当你有一个大文件时,快照包含这个文件的一个压缩版本(或者如果文件没有改变,则指向文件blob的指针)。 存储库快照以.git文件夹下的图存储。 因此,如果文件“很大”,存储库大小将迅速增长。 有多个标准来确定是否使用Git LFS存储文件。 文件的大小。 I ...
  • 如果您可以访问python解释器,则可以使用git-lfs-fetch.py下载文件。 If you have access to a python interpreter you can use git-lfs-fetch.py to download the files.
  • 如果您将TFS与LFS一起使用,那么这些文件将存储在TFS中,而不是存储在s3中。 Here is what I came across during my research: TFS 2015 uses the database to store large files by default when using git lfs. VSTS supports git lfs & offers free storage right now. To use a AWS S3 Storage with git ...
  • 仅更新当前提交 如果您想要移除LFS,但不担心修复整个git历史记录,可以执行以下操作; git lfs uninstall touch **/* git commit -a 这将卸载LFS支持,触摸每一个文件(以便git认识到已经改变),然后全部提交。 如果你喜欢,你可以更具体(例如, **/*.png例如)。 请注意,使用**需要启用扩展的glob支持(bash上的shopt -s globstar ) 更新整个历史 这对我有用 - 但它会引发很多错误(我认为每次提交文件时都没有将错误添加到LFS中) ...
  • 作为一项规则,当你运行任何Git不知道的任意命令作为内置(或者甚至是Git 确实知道的内置实际命令)时,例如: git asdf Git将在$PATH搜索名为git-asdf的程序。 不过,在进行此搜索之前,Git会插入其内置的git-core目录: $ git --exec-path /usr/lib/git-core (在Ubuntu VM上;在我的Mac上它当前是/usr/local/Cellar/git/2.15.1_1/libexec/git-core因为那是我在那里安装的最后一次更新)。 除 ...
  • 关于docker docker/hub-feedback lfs没有任何内容。 docker/docs.docker.com / notary或docker/docs.docker.com或docker/docs.docker.com docker/distribution也没有任何内容 Docker Hub自动构建 “允许您使用Docker Hub的构建集群自动从包含Dockerfile的GitHub或Bitbucket存储库创建映像”。 由于Git LFS只是GitHub上的官方版本,因此在过去的14天 ...
  • 看起来构建失败的原因是: standard_init_linux.go:178: exec user process caused "exec format error" 你的基本图像是resin/rpi-raspbian:jessie是一个ARM图像。 Docker Hub是一个x86_64构建平台。 因此,您将无法使用Docker Hub来构建图像。 It looks like the cause of the build failure is: standard_init_linux.go:178: ...
  • 这是我如何让git lfs在机器人中工作。 首先,我编辑了我的机器人“在集成之前”触发器运行脚本,如下所示: #!/bin/bash export PATH="$PATH:/opt/local/bin:/opt/local/sbin:/usr/local/bin" (cd ${XCS_SOURCE_DIR}/My-Project_Dir/My-Subfolder-Dir; sudo git lfs pull) 我们在用户/本地/ bin中导出PATH b / c git lfs(这些其他位置可能适用,具体 ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)