Friends, Technology, Web2.0 - What I am reading

    [Home] [Recent] [Site Map]

   

View Code, ViewEngine Code

又快有1个月没写东西了,不是因为懒,而是忙于学习。ASP.NET MVC Preview 2已经发布一段时间了,在网上看到了一些相关的文章,但是由于是Preview的版本,没有SDK,学习很辛苦。很多文章都讲了Route的用法,Google一下太多了。但是我遇到了一些问题却始终没有找到答案,先在这里分享一下,看看大家有没有更好的方法。

我们在做一个web app的时候,通常会有很多的模块,例如MIS系统,里面会有CRM\HR等,这时再进行构架的时候,就会出现这样一个问题可能在不同的模块中都会有HomeController,当然我们可以在Project中添加文件夹,并使用不同的名称空间来解决,而且在URL上也可以自己添加Route来搞定。这些在Google都能找到解决方案,但是在View层的问题就麻烦了。类似于Controller,不同的模块都有Index视图,而默认情况下视图是依赖于文件系统的,而且还有。。。(下面说),view code 先,

 public class WebFormViewLocator : ViewLocator {
        public WebFormViewLocator() {
            ViewLocationFormats = new[] {
                "~/Views/{1}/{0}.aspx",
                "~/Views/{1}/{0}.ascx",
                "~/Views/Shared/{0}.aspx",
                "~/Views/Shared/{0}.ascx"
            };
            MasterLocationFormats = new[] {
                "~/Views/{1}/{0}.master",
                "~/Views/Shared/{0}.master"
            };
        }
    }

这个部分是MVC中WebFormViewLocator的构造函数,大家可以看出一个问题在,在Controller中调用RenderView的时候你只能指定View的Name,然后默认情况下WebFormViewEngine会调用IViewLocator的GetViewLocation方法,这个时候传入的参数就是viewContext和viewContex.ViewName,所以如果你的View没有按照这个格式保存在相应的目录中就会出现问题。

Code看过了,那问题就来了应用稍微复杂一些,我们的View就会有很多了中不能按照这种发式进行开发呀。

接下来又要仔细的看看Source Code了,ViewLocator在GetPaht函数中调用了一个IsSpecificPath的函数

        private static bool IsSpecificPath(string name) {
            return
                name.StartsWith("~", StringComparison.Ordinal) ||
                name.StartsWith("/", StringComparison.Ordinal);
        }

这回看明白了,只要在RenderView的时候按照这个规则写上路径就可以了,当然要添加.aspx后缀名。

没有SDK的日子。。。。。。


>>Source Link
>>Blog: joycode
>>Publish Date: 4/10/2008 7:02:44 AM
>>Keywords: code view

Related Posts
>>每日美味 [2007-06-03]:zheng @ del.icio.us #
    Mahalo and Friends: 10 People Powered Search Engines Top 15 Google Street View Sightings 北京“爱心”难敌微软I’m 被指缺乏时尚感(图)--北方网-IT浪潮www.helpwy.com 参与爱心签名王越走了。。。 Facebook | X Me第一个开发于facebook上的应用? Wakoopa - Sof
>>BritePic — photography may never be the same #
    Advertising start-up AdBrite has launched an elegant way to put ads on digital photos, a potentially revolutionary way for photographers to make money. The feature, called BritePic, was released five
>>Mix07 Keynote Silverlight demo with source code #
    http://blogs.msdn.com/delay/archive/2007/05/01/the... Source code click here to download the complete source code for this demo application
>>Caption Contest - Office 2.0 Ticket Giveaway #
    Read/WriteWeb has 1 free ticket to give away for the Under The Radar Office 2.0 conference, to be held on March 23 at the Microsoft Campus in Mountain View. More details at the Under The Radar blog. T
>>Track Your Google Docs With Analytics #
    A new option has just appeared in the Google Docs Settings page for tracking your published documents. Simply enter one of your Google Analytics account tracking codes and you"ll apparently be able to
>>All The Code – New Search Engine for Programmers #
    The announcement in TechCrunch about the launch of All The Code prompted a deeper dive into this highly specialized type of vertical search. All The Code at this time is a source code search engine
>>Winner of Office 2.0 Caption Contest #
    We had an awesome response to our caption contest on Monday - over 80 comments! The Under The Radar folks and myself had a tough choice deciding... but the winner of the free ticket to the Under The R
>>DataSet vs Custom Entity 阅读资料 #
    上一篇blog还是在6月底写的,然后就是第一年的performance review,再有beta版的开发工作,一直都没有更新。 到今天Windows Live Data的Beta基本已尘埃落定(其实两周前已经code freeze了,我又花了一周解决了一些deployment configuration的问题),10月17日是预定的发布日,剩下的这两个星期除了紧急的bug fix外,主要的精
>>Code Camp #
    以前在北京的时候, 虽然没有参加过宝玉同学组织的.Net User Group 的活动,但是从日常工作中,也从宝玉同学的介绍中了解了一二。印象中, 在北京似乎是没有组织过Code Camp 的活动过。 Code Camp 是最初2004年底的时候 在开发者中逐渐成形的一种活动, 这项活动的最大特点有以下几个显著的特点. 由开发者社区组织,面向开发者的社区 永远免费 没有市

Other Posts:
>>Framework Design Studio发布了
>>Subtext从睡眠中醒来
>>MFC Feature Pack发布
>>IE 8 Beta 1简体中文版正式发布
>>给 VSTO 插件、文档传送参数
>>SharePoint News
>>Unity DI 容器 1.0 发布了
>>技巧/诀窍: 创建和使用Silverlight和WPF 用户控件
>>Silverlight技巧,诀窍,教程和链接
>>[Best Practice]给你的SharePoint Web Application设置单独的应用程序池
>>在Silverlight中做单元测试
>>VSTO 也有官方中文书啦!!!


Month Archives:

Top Tags:
Company & Product Profiles Google Internet Technology Search feature Business and Technology Web2.0 column analysis 服务介绍 application letter comment 业界信息 news Startups deal Search Headlines China2.0 產業策進 Social Network 未來趨勢 widget 創投 news_in 业界动态 SEW Experts 創業案例 Web 2.0 News & Ideas


@2007 All rights Reserved