约定优于在ASP.NET MVC配置 [英] Convention over configuration in ASP.NET MVC

查看:90
本文介绍了约定优于在ASP.NET MVC配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的ASP.NET MVC,和我同平台的清晰度至今pssed很IM $ P $。但是,我发现不舒服的一个方面。

I am relatively new to ASP.NET MVC, and am very impressed with the clarity of the platform so far. However, there is one aspect that I find uncomfortable.

起初,我接受了这个事实,当我说

At first, I accepted the fact that when I say

return View();

我打电话,返回一个ActionResult一个辅助方法,使一些假设关于哪个视图present,路由值等,但最近我一直在写code,看起来更像是这样的:

I am calling a helper method that returns an ActionResult, and makes some assumptions about which view to present, route values, etc. But lately I have been writing code that looks more like this:

return View("Index", new { id = myID })

因为它是清醒时立即给我发生了什么事通过读取一行code的。

because it is immediately clear to me what's happening by reading that single line of code.

最近我一直在用事实挣扎,我可以对选项卡中打开一个的Index.aspx 观点,我不能立即告诉它从何而来,因为IDE不突出在对象资源管理器的当前标签。我还没有使出改变文件的名称为 ControllerNameIndex.ASPX ,但我把标题是更具体的看法。不过,它没有太多帮助。

Lately I have been struggling with the fact that I can have an Index.ASPX view open on the tabs, and I can't immediately tell where it comes from because the IDE doesn't highlight the current tab in the Object Explorer. I haven't resorted to changing the names of the files to ControllerNameIndex.ASPX, but I do put a title in the view that is more specific. Still, it doesn't help much.

你如何与这些类型的歧义处理?

How do you deal with these kinds of ambiguities?

推荐答案

我觉得你回答了你自己的问题。

I think you answered your own question.

有没有硬性规定preventing你调用你的意见非常具体的名称,如ListOfFooBars或EditFizzBu​​zz或AddNewGeeblup。默认视图引擎的命名约定只规定有意见下对应的型号名称的文件夹,并有对应于您的视图名称文件夹下一个ASPX或ASPC文件。

There's no hard rule preventing you from calling your views very specific names, such as "ListOfFooBars" or "EditFizzBuzz" or "AddNewGeeblup". The naming convention for the default view engine only specifies that there's a folder corresponding to your model name under views, and there's an ASPX or ASPC file under that folder that corresponds to your view name.

这篇关于约定优于在ASP.NET MVC配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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