如何使智能感知与RazorEngine一起使用? [英] How to make intellisense works with RazorEngine?
问题描述
我正在尝试配置RazorEngine,以使intellisense在视图上起作用.我使用nuget添加RazorEngine和Microsoft.AspNet.Mvc.我创建了TestView.cshtml并声明了@model MyModel
,但它显示了The name 'model' does not exist in the current context
.我也不能在视图内部使用智能感知.
I am trying to configure RazorEngine so that intellisense works on views. I add RazorEngine and Microsoft.AspNet.Mvc using nuget. I create TestView.cshtml and declare @model MyModel
but it says The name 'model' does not exist in the current context
. I also cannot use intellisense inside the view.
我在这里错过任何一步了吗?如何在视图中启用智能感知?
Do I miss any step here? How to enable intellisense in the View?
推荐答案
您可以使用
@using RazorEngine.Templating
@using Namespace.Of.My.Model
@inherits TemplateBase<MyModel>
位于模板顶部.
这在带有Visual Studio 2013的新控制台应用程序上正常工作(添加对RazorEngine的引用之后). 有关文档,请此处.
This works fine on a new Console Application with Visual Studio 2013 (after adding a reference to RazorEngine). The documentation for this is here.
我注意到这仅在将RazorEngine项目添加到解决方案并直接引用时才有效.如果您使用NuGet软件包,则还需要确保以下条件之一使其起作用:
I noticed that this only works when the RazorEngine project is added to the solution and directly referenced. If you use the NuGet package you additionally need to ensure one of the following to make it work:
- 您的项目输出路径设置为
bin\
,而不是bin\Debug\
和bin\Release\
. - 将
RazorEngine.dll
和System.Web.Razor.dll
复制到bin\
- Your project output path is set to
bin\
instead ofbin\Debug\
andbin\Release\
. - Copy
RazorEngine.dll
andSystem.Web.Razor.dll
tobin\
这篇关于如何使智能感知与RazorEngine一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!