知乎周源微信

I was literally in the middle of writing the post when I saw a message from Andrew Davey about how he had implemented the same idea! Of course, his is way better, so I got to code via subtraction. That means subtracting out the crap I had written in a few minutes and dig into his code.

当我看到安德鲁·戴维( Andrew Davey)关于他如何实现相同想法的消息时,我确实在写这篇文章。 当然,他的方法更好,所以我必须通过减法进行编码。 这意味着要减去我几分钟内写的废话,然后深入研究他的代码。

There are no unique ideas, right? ;) Either way, it's fun when the same idea is being thought about simultaneously.

没有独特的主意吧? ;)无论哪种方式,同时考虑同一想法都会很有趣。

Here's the general concept. A few weeks back I was talking with Avner Aharoni, a Language Program Manager, and he had been kicking around the idea of VB9's XML Literals making friendlier Views within ASP.NET MVC.

这是一般概念。 几周前,我正在与语言程序经理Avner Aharoni进行交谈,他一直在探讨VB9的XML Literal在ASP.NET MVC中创建更友好的视图的想法。

I've blogged about VB9's rocking sweet XML support before. It lets you create XML like this. Note the lack of strings...the XML is there in the language and the compiler and intellisense are all aware of it.

之前,我已经写过关于VB9出色的XML支持的博客。 它使您可以像这样创建XML。 注意缺少字符串...语言中存在XML,编译器和intellisense都知道它。

 Dim books = <bookstore xmlns="http://examples.books.com">                        <book publicationdate=<%= publicationdate %> ISBN=<%= isbn %>>                            <title>ASP.NET Book</title>                            <price><%= price %></price>                            <author>                                <first-name><%= a.FirstName %></first-name>                                <last-name><%= a.LastName %></last-name>                            </author>                        </book>                    </bookstore>

ASP.NET MVC中的视图 (Views in ASP.NET MVC)

Starting with the Northwind ASP.NET MVC Sample Code for Preview 3 that Phil updated, let's look at the List View:

从Phil更新的预览版3的Northwind ASP.NET MVC示例代码开始,让我们看一下列表视图:

<asp:Content ContentPlaceHolderID="MainContent" runat="server">    <h2><%=ViewData.CategoryName %></h2>    <ul>        <% foreach (Product product in ViewData.Model.Products.Model) { %>            <li id="prod<%= product.ProductID %>">                <%= product.ProductName %>                 <span class="editlink"">                    (<%= Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID })%>)                </span>            </li>        <% } %>    </ul>    <%= Html.ActionLink("Add New Product", new { Action="New" }) %></asp:Content>

This is straight from the ASPX page with inline C#.

这直接来自带有内联C#的ASPX页面。

使用VB9的XML文字支持的ASP.NET MVC视图 (ASP.NET MVC Views using VB9's XML Literal Support)

Now, we thought it'd be cool/interesting/potentially-something if we could use the XML Literal support to get, as Andrew puts it "compiled, strongly typed, intellisense friendly views." Sure, we mostly get that with the ASPX pages, but perhaps this would be better/easier/something? Keep in mind here that we're playing.

现在,我们认为如果可以使用XML Literal支持来获取(如安德鲁所说)“很酷,很有趣/很有可能”,就像安德鲁所说的那样:“经过编译,强类型,具有智能感知的视图”。 当然,我们大多数都是通过ASPX页面得到的,但这也许会更好/更容易/更合适? 请记住,我们正在玩。

Your opinions on if this is a good idea or something to move forward would be useful. Leave comments and I'll compile and give them directly on to the VB and MVC team(s)! Remember, it can look like however you think it should, so don't be constrained by my spike or Andrew's.

您对于这是一个好主意还是要前进的观点将很有用。 留下评论,我将进行编译并将其直接交给VB和MVC团队! 请记住,它看起来像您认为应该的那样,所以不要被我的尖峰或安德鲁的约束。

Here's why Andrew thinks it's cool, quoted from a post on the ALT.NET mailing list:

从ALT.NET邮件列表中的帖子中引用安德鲁认为这很酷的原因:

Some key features I've used.
- <%= From ... Select ... %> to create repeated elements
- VB's ternary "If" operator for conditional output
- X-linq to post process the HTML before sending it
- choose between indented and compressed XML output
- modules of functions as "controls" - it's so simple :)

我使用过的一些关键功能。 -<%= From ...选择...%>以创建重复的元素-VB的三元“ If”运算符,用于条件输出-X-linq在发送HTML之前对其进行后期处理-在缩进和压缩的XML输出之间选择-作为“控件”的功能模块-非常简单:)

Here's what my solution looks like in Visual Studio. See how the ListVB.aspx has no "+" sign. There's no code-behind .cs file there even though this is a C# project. The meat of the View is in another assembly (although you could conceivably do something freaky and get VB and C# to live in the same assembly (be sure to read the comments)).

这是我的解决方案在Visual Studio中的外观。 查看ListVB.aspx如何没有“ +”号。 即使这是C#项目,也没有在.cs文件后面的代码。 View的内容在另一个程序集中(尽管可以想象,您可以做一些怪异的事情,并使VB和C#驻留在同一程序集中(请务必阅读注释))。

Actually, the ListVB.aspx file is VB, not C# and refers not to to a code-behind, but another class in another DLL, specifically the VBViews assembly.

实际上,ListVB.aspx文件是VB,而不是C#,并且不是引用到后台代码,而是引用另一个DLL中的另一个类,尤其是VBViews程序集。

<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="VBViews.ListVB" Title="Products" %><%@ Import Namespace="NorthwindModel" %><%@ Import Namespace="System.Collections.Generic" %><asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">    <h2><%=ViewData.Model.CategoryName%></h2>    <% = GetList() %></asp:Content>

Here's the Visual Basic code in the other assembly.

这是另一个程序集中的Visual Basic代码。

Imports System.Xml.LinqImports NorthwindDemo.Models

Partial Public Class ListVB    Inherits System.Web.Mvc.ViewPage

    Function GetList() As XElement        Dim c As Category = CType(ViewData.Model, Category)        Return <ul><%= From product In c.Products _                       Select _                       <li id=<%= "prod" & product.ProductID %>>                           <span class="editlink">                               <a href=<%= "/Products/Edit/" & product.ProductID %>>                                   <%= product.ProductName %>                               </a>                           </span>                       </li> %>               </ul>    End FunctionEnd Class

This won't really be clear without some syntax highlighting to make the point, so here it is again, but this time as a screenshot. See now the VB code, XML and <% %> blocks are all together in same line? VB is just generating XElement's which in turn will turn into a string when "rendered" by the ASPX page.

如果没有突出显示语法,这实际上并不清楚,所以再次出现,但这一次是屏幕截图。 现在看到VB代码,XML和<%%>块都在同一行中吗? VB只是生成XElement,当由ASPX页面“呈现”时,XElement又将变成字符串。

Andrew将VB9 XML文字列为ASP.NET MVC视图的第二名 (Andrew's Take #2 on the VB9 XML Literals as ASP.NET MVC Views)

Andrew Davey's NRest project is more than just VB9 Views. It's a REST web framework for ASP.NET using the Nemerle programming language (using the May CTP). You can browser or GET his code with SVN here: http://svn.assembla.com/svn/nrest/trunk/. It's also a nicely laid out solution that uses the Ninject IOC but I'll cover that later. Do check out Andrew's screencast about his NRest project.

Andrew Davey的NRest项目不仅仅是VB9视图。 它是使用Nemerle编程语言(使用May CTP)的ASP.NET REST Web框架。 您可以在以下位置使用SVN浏览器或获取他的代码: http : //svn.assembla.com/svn/nrest/trunk/ 。 这也是一个使用Ninject IOC的布局很好的解决方案,但稍后会介绍。 请查看安德鲁关于NRest项目的截屏视频。

His code is a mix of C#, Nemerle and VB. The Website, Tests and Services are in C# and the Ninject modules are in Nemerle, along with the meat of the main NRest project. I think he could have used more of System.MVC, specifically the View Engines, that he did, but I'm still grokking his intent.

他的代码混合了C#,Nemerle和VB。 网站,测试和服务均位于C#中,Ninject模块位于Nemerle中,以及主要NRest项目的内容。 我认为他本可以使用更多的System.MVC,尤其是View Engines,但我仍然对他的意图不满意。

He's got a hierarchy in VB with a MainPageBase, Page, in order to achieve a kind of Master Pages:

为了获得一种母版页,他在VB中拥有一个MainPageBase的层次结构,即页面:

Public Class MainPageBase(Of TChrome As MainChrome, TContent)    Inherits Page(Of TChrome, TContent)

    Public Overrides Function GetHtml() As XElement        Return _        <html>            <head>                <title><%= Chrome.Title %></title>                <link href="/styles/demo.css" type="text/css" rel="Stylesheet"/>                <%= GetHeadContents().Elements() %>            </head>            <body>                <h1><%= Chrome.Title %></h1>                <%= GetBodyContents().Elements() %>            </body>        </html>    End Function

    Public Overridable Function GetHeadContents() As XElement        Return <_></_>    End Function

    Public Overridable Function GetBodyContents() As XElement        Return <_></_>    End Function

End Class

So a Hello World page in VB would be very simple, just this:

因此,VB中的Hello World页面将非常简单,仅此:

Public Class CustomerPage    Inherits MainPageBase(Of CustomerPageData)

    Public Overrides Function GetBodyContents() As XElement        Return _        <_>            <p>Hello <%= Content.FirstName & " " & Content.LastName %></p>        </_>    End FunctionEnd Class

All of this is a work in progress, but it's really cool that we're all trying to push the envelope and not afraid to try crazy stuff in order to make things better. It'll be cool for me to read this post in a year and either say "ew" or "cool!" depending on what direction we all went.

所有这一切仍在进行中,但是我们都在努力突破极限,而不是为了提高条件而疯狂尝试疯狂的东西,这真是太酷了。 对我来说,一年内读这篇文章并说“ ew”或“ cool!”真是太酷了! 取决于我们所有人走的方向。

Have you done anything cool or crazy with Views and ViewEngines, Dear Reader?

亲爱的读者,您是否对Views和ViewEngines做过酷或疯狂的事情?

Related Posts

相关文章

  • Is rooting for Visual Basic like rooting for the Red Sox?

    为Visual Basic扎根就像是为Red Sox扎根一样?

  • XLINQ to XML support in VB9

    VB9中的XLINQ to XML支持

  • Mixing Languages in a Single Assembly in Visual Studio seamlessly with ILMerge and MSBuild

    使用ILMerge和MSBuild在Visual Studio中的单个程序集中无缝混合语言

  • NRest Screencast

    NRest截屏

翻译自: https://www.hanselman.com/blog/the-weekly-source-code-30-vbnet-with-xml-literals-as-a-view-engine-for-aspnet-mvc

知乎周源微信

知乎周源微信_每周源代码30-具有XML文字的VB.NET作为ASP.NET MVC的视图引擎相关推荐

  1. 知乎周源微信_每周源代码7

    知乎周源微信 In my new ongoing quest to read source code to be a better developer, I now present the seven ...

  2. 知乎周源微信_每周源代码36-PDC,BabySmash和Silverlight图表

    知乎周源微信 First, let me remind you that in my new ongoing quest to read source code to be a better deve ...

  3. 知乎周源微信_每周源代码33-Google Chrome中的Microsoft Open Source

    知乎周源微信 First, let me remind you that in my new ongoing quest to read source code to be a better deve ...

  4. 知乎周源微信_每周源代码42-树修剪,插件和MEF

    知乎周源微信 I really advocate folks reading as much source as they can because you become a better writer ...

  5. 知乎周源微信_每周源代码56-Visual Studio 2010和.NET Framework 4培训套件-代码合同,并行框架和COM互操作...

    知乎周源微信 Do you like a big pile of source code? Well, there is an imperial buttload of source in the V ...

  6. 知乎周源微信_每周源代码39-Silverlight 3中的Commodore 64仿真器

    知乎周源微信 I had the pleasure of interviewing Pete Brown this last week and talking about the Silverligh ...

  7. 知乎周源微信_每周源代码24-可扩展性版本-.NET中的插件,提供程序,属性,插件和模块...

    知乎周源微信 I've been getting more and more interested in how folks extend their applications using plugi ...

  8. 知乎周源微信_每周源代码18-深度缩放(Seadragon)Silverlight 2 MultiScaleImage鼠标滚轮缩放和平移版...

    知乎周源微信 Dear Reader, I present to you eighteenth in a infinite number of posts of "The Weekly So ...

  9. 知乎周源微信_每周源代码59-开源宝藏:具有讽刺意味的.NET语言实现工具包

    知乎周源微信 One of the best, if not the best way to sharpen the saw and keep your software development sk ...

最新文章

  1. [剑指Offer]5.二维数组中的查找
  2. 可信计算 沈昌祥_沈昌祥院士在南宁开展网络安全前沿知识讲座
  3. 360急速浏览器JS的调试
  4. 信号与系统 chapter10 系统的初值问题与系数匹配法
  5. 杨宏宇:腾讯多模态内容理解技术及应用
  6. html js关闭浏览器,js关闭页面(兼容浏览器)
  7. c/c++_消除非标准警告
  8. 产品经理 需求 项目经理 选择_【产品】产品和项目,产品经理和项目经理 区别...
  9. SI4463模块使用心得(无线协议)
  10. 基于FPGA的cameralink编解码测试系统设计
  11. web前端期末大作业:美食文化网页设计与实现——美食餐厅三级(HTML+CSS+JavaScript)
  12. 中维监控显示无法连接服务器失败,中维远程监控系统服务器端
  13. 从NCBI中查看已发现的基因可变剪接
  14. 一文搞懂经济数据中M0 M1 M2
  15. android定时器课设报告,数显定时器课程设计报告.doc
  16. 软件工程和软件开发过程
  17. PT100三线制恒流源接法
  18. 精华|风控相关欺诈防范要点(规则制定)
  19. MySQL--数据库、表基本操作
  20. parseInt()和parseFloat()的解析原理

热门文章

  1. PL/SQL Developer设置日期格式
  2. 非上海户籍人员在上海买房需要啥条件?
  3. 3.16下午 王希伟网课+笔记
  4. kuangbin 专题一 简单搜索
  5. selinux--初篇
  6. AIX系统管理界面工具SMIT快捷方式
  7. 软件设计模式与体系结构(上)
  8. 国际经济学 简答计算
  9. 盈帆报表软件制作编号报表(报表工具)
  10. 创客学院9天C语言五