我想下载并安装ASP.Net MVC的剃须刀视图引擎2.从哪里我可以下载和安装?如何下载Razor查看引擎
回答
可能有点过时,但你也许应该看看这篇文章。
http://stefan.rusek.org/Posts/Using-Razor-with-ASP-NET-MVC-in-Four-Easy-Steps/26/
剃刀能够独立运行,因此,完全可以自己提供的布线的。不管你是否需要使用.NET4,我都不是100%确定的。在另一个说明中,MVC3处于RC状态,并具有Go-Live许可证,您可以在技术上立即开始使用,并在RTM命中(很快)时立即升级。
利用Codeplex的Matthew Abbott's和My Razor View Engine。你可以做以下事情。它不支持模型或布局页面,但如果您选择走这条路线,它会让您朝着正确的方向前进。坦率地说,当时间准备就绪时,我只会更新到MVC 3。这段代码在http://buildstarted.com/2010/11/22/making-your-own-viewengine-with-markdown/
是基于我的博客文章你必须把下面几行添加到您的Global.asax:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine.RazorViewEngine());
,除非你想两个引擎在这种情况下,只是删除Clear()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Hosting;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace RazorViewEngine {
/// <summary>
/// ViewEngine for the RazorView. Provides basic file handling to load views.
/// </summary>
public class RazorViewEngine : IViewEngine {
string[] SearchLocations { get; set; }
Tuple<string, string, RazorView> Cache { get; set; }
VirtualPathProvider VirtualPathProvider { get; set; }
public RazorViewEngine() {
//{1} == Controller name
//{0} == View name
SearchLocations = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml",
};
VirtualPathProvider = HostingEnvironment.VirtualPathProvider;
}
#region IViewEngine Members
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) {
return CreateView(controllerContext, partialViewName, null, null, useCache);
}
public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) {
return CreateView(controllerContext, viewName, masterName, GetLayoutPath(controllerContext), useCache);
}
/// <summary>
/// Meat of the FindView methods.
/// </summary>
/// <param name="controllerContext">The current controller context for this request.</param>
/// <param name="viewName">The requested view name. </param>
/// <param name="masterName">The master page view name (currently unused)</param>
/// <param name="layoutPath">The layout path location (Replaces the masterpage in other view engines)</param>
/// <param name="useCache">Cache the viewpage?</param>
/// <remarks>The layout path is currently hardcoded to "Layout" and will look in the SearchLocations for that path</remarks>
/// <returns>Returns a ViewEngineResult with the requested view</returns>
public ViewEngineResult CreateView(ControllerContext controllerContext, string viewName, string masterName, string layoutPath, bool useCache) {
//grab the current controller from the route data
string controllerName = controllerContext.RouteData.GetRequiredString("controller");
//for proper error handling we need to return a list of locations we attempted to search for the view
string[] SearchedLocations;
//get the actual path of the view - returns null if none is found
string viewPath = GetViewPath(viewName, controllerName, out SearchedLocations);
if (viewPath != null) {
RazorView view = new RazorView(this, controllerContext, viewPath, layoutPath);
return new ViewEngineResult(view, this);
}
//we couldn't find the view - return an array of all locations we've looked in
return new ViewEngineResult(SearchedLocations);
}
/// <summary>
/// Look for the view in the current file system
/// </summary>
/// <param name="viewName">The name of the View you're looking for</param>
/// <param name="controllerName">Current controller name</param>
/// <param name="SearchedLocations">out a list of locations searched</param>
/// <returns>A string value of the relative path</returns>
public string GetViewPath(string viewName, string controllerName, out string[] SearchedLocations) {
return FindPath(viewName, controllerName, out SearchedLocations);
}
/// <summary>
/// Look for the view in the current file system
/// </summary>
/// <param name="viewName">The name of the View you're looking for</param>
/// <param name="controllerName">Current controller name</param>
/// <param name="SearchedLocations">out a list of locations searched</param>
/// <returns>A string value of the relative path</returns>
public string FindPath(string viewName, string controllerName, out string[] SearchedLocations) {
SearchedLocations = new string[SearchLocations.Length];
for (int i = 0; i < SearchLocations.Length; i++) {
string virtualPath = string.Format(SearchLocations[i], viewName, controllerName);
SearchedLocations[i] = virtualPath;
//check the active VirtualPathProvider if the file exists
if (VirtualPathProvider.FileExists(virtualPath)) {
//add it to cache - not currently implemented
return VirtualPathProvider.GetFile(virtualPath).VirtualPath;
}
}
return null;
}
/// <summary>
/// Get the layout virtual path
/// </summary>
/// <param name="controllerContext">The current Controller context for this request</param>
/// <returns>A string virtual path</returns>
public string GetLayoutPath(ControllerContext controllerContext) {
//This should probably be added to a list of locations - I'm not sure exactly
//what I need to do with this yet.
string[] locations;
return FindPath("Layout", controllerContext.RouteData.GetRequiredString("controller"), out locations);
}
/// <summary>
/// Current irrelevant
/// </summary>
/// <param name="controllerContext">The active controller context</param>
/// <param name="view">View to release</param>
public void ReleaseView(ControllerContext controllerContext, IView view) {
IDisposable disposable = view as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
#endregion
}
/// <summary>
/// Implements IView and renders a Razor
/// </summary>
public class RazorView : IView {
ControllerContext ControllerContext;
string ViewPath;
string LayoutPath;
RazorViewEngine Engine;
public RazorView(RazorViewEngine engine, ControllerContext controllerContext, string viewPath, string layoutPath) {
//load the file
this.ControllerContext = controllerContext;
this.ViewPath = viewPath;
this.LayoutPath = layoutPath;
this.Engine = engine;
}
#region IView Members
/// <summary>
/// Converts Razor to html and writes it to the passed in writer
/// </summary>
/// <param name="viewContext"></param>
/// <param name="writer"></param>
public void Render(ViewContext viewContext, System.IO.TextWriter writer) {
//View contents
string contents = new StreamReader(VirtualPathProvider.OpenFile(ViewPath)).ReadToEnd();
string layoutContents = LayoutPath == null
? null
: new StreamReader(VirtualPathProvider.OpenFile(LayoutPath)).ReadToEnd();
contents = Parse(contents);
string output;
output = contents;
writer.Write(output);
}
/// <summary>
/// Converts Razor to html
/// </summary>
/// <param name="Razor">Razor text</param>
/// <returns>Html formatted Razor text</returns>
string Parse(string Razor) {
//Where do I get the model From
return RazorEngine.Razor.Parse(Razor);
}
#endregion
}
}
我已经在部分代码中设置了一个完全不同的视图引擎(http://tqcblog.com/2011/01/23/precompiled-razor-for-shared-views-and-mono/)。如果使用预编译来减少运行时依赖关系,支持模型,布局等等会更容易一些。我还没有尝试mvc2/.net3.5组合,但它应该不会超过一些参考更改。 – 2011-01-23 03:48:14
获得MVC Razor引擎并学习如何使用它的最佳方式是从Scot Gu!整个剃刀项目的导师。他的博客文章http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx 非常容易遵循,并教你如何管理VS中的包管理器Consel的脚手架过程。
- 1. MVC Razor查看引擎,在引号之间添加逻辑
- 2. Razor中的全局变量查看引擎
- 3. Razor中的Javascript Intellisense查看引擎子页面
- 4. 设置foreach中的var值 - Razor查看引擎
- 5. 如何下载Abbyy FineReader引擎
- 6. 查看引擎ASP.net MVC
- 7. Nustache查看引擎ArrayTypeMismatchException
- 8. 在MVC3 Razor视图引擎
- 9. Razor视图引擎RenderSection
- 10. 与Razor视图引擎
- 11. Razor视图引擎语法
- 12. 使用Razor查看引擎与南希,.cshtml不是可用的扩展
- 13. 如何查看下载过程?
- 14. 如何使查看响应可下载?
- 15. Asp.net MVC 3查看引擎错误
- 16. MVC 4查看引擎搜索位置
- 17. 查看引擎下拉列表不存在添加视图
- 18. MVC3负载动态属性到JavaScript使用Razor视图引擎
- 19. 将视图引擎升级到Razor
- 20. 主持ASP.NET MVC 3 Razor引擎网站
- 21. 有鉴于MVC3 Razor视图引擎
- 22. 在Mac上使用Razor模板引擎
- 23. MVC3 Razor查看优化
- 24. 搜索引擎如何查看本地化的Django网站?
- 25. 如何使用Razor视图引擎声明评论?
- 26. 如何正确渲染变量而不会混淆Razor引擎?
- 27. 如何注册组件Razor视图引擎
- 28. 加载CouchDB查看索引
- 29. 如何从谷歌应用引擎提供APK文件下载
- 30. 我该如何下载虚幻引擎3
的视图引擎System.Web.Razor * does * target v 4.0的框架。鉴于MVC3的RTM迫在眉睫,我同意在这个阶段试图将Razor插入MVC2应用程序似乎有点毫无意义。 – 2011-01-10 13:50:11