如何使输入构建器 (MVC Contrib) 与 Spark View Engine 配合使用?
今天我花了三个小时尝试转换项目 MvcContrib.Samples.InputBuilders,包含在 MVC Contrib使其与 Spark View Engine 一起使用,但到目前为止还无法做到这一点。
有人知道为什么这两个人不能相处吗?
我所做的更改
InputForm.spark:
<viewdata model="SampleInput" />
!{Html.InputForm()}
Global.asax.cs:
...
protected void Application_Start() {
RegisterRoutes(RouteTable.Routes);
InputBuilder.BootStrap();
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new SparkViewFactory());
}
Web.config:
...
<spark>
<compilation debug="true"/>
<pages automaticEncoding="true">
<namespaces>
<add namespace="System"/>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Linq"/>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="MvcContrib.UI.InputBuilder"/>
<add namespace="MvcContrib.UI.InputBuilder.Views"/>
<add namespace="Web.Models"/>
</namespaces>
</pages>
</spark>
(我从示例项目中复制了最后三个命名空间。)
错误我得到
根据我在 Global.asax.cs 中设置 Spark/InputBuilder 的顺序,我得到两个不同的异常。
如果我首先设置 InputBuilder,然后设置 Spark(代码如上所示):
错误CS1061: “System.Web.Mvc.HtmlHelper”没有 包含“InputForm”的定义 并且没有扩展方法“InputForm” 接受类型的第一个参数 “System.Web.Mvc.HtmlHelper”可能是 找到了(您是否缺少使用 指令还是程序集引用?)
如果我首先设置 Spark,然后设置 InputBuilder:
视图“InputForm”或其主视图 找不到。下列 搜索位置:
~/Views/Home/InputForm.aspx
~/Views/Shared/InputForm.aspx
~/Views/InputBuilders/InputForm.aspx
~/Views/Home/InputForm.ascx
~/Views/Shared/InputForm.ascx
Today I spent a good three hours trying to convert the project MvcContrib.Samples.InputBuilders, included in MVC Contrib to make it work with Spark View Engine, but so far was unable to do so.
Does anybody have a clue why these two just won't get along?
Changes I've made
InputForm.spark:
<viewdata model="SampleInput" />
!{Html.InputForm()}
Global.asax.cs:
...
protected void Application_Start() {
RegisterRoutes(RouteTable.Routes);
InputBuilder.BootStrap();
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new SparkViewFactory());
}
Web.config:
...
<spark>
<compilation debug="true"/>
<pages automaticEncoding="true">
<namespaces>
<add namespace="System"/>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Linq"/>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="MvcContrib.UI.InputBuilder"/>
<add namespace="MvcContrib.UI.InputBuilder.Views"/>
<add namespace="Web.Models"/>
</namespaces>
</pages>
</spark>
(I copied the last three namespaces from the sample project.)
Errors I'm getting
Depending on the order in which I setup Spark/InputBuilder in Global.asax.cs, I get two different exceptions.
If I first setup InputBuilder, then Spark (code shown above):
error CS1061:
'System.Web.Mvc.HtmlHelper' does not
contain a definition for 'InputForm'
and no extension method 'InputForm'
accepting a first argument of type
'System.Web.Mvc.HtmlHelper' could be
found (are you missing a using
directive or an assembly reference?)
If I first setup Spark, then InputBuilder:
The view 'InputForm' or its master
could not be found. The following
locations were searched:~/Views/Home/InputForm.aspx
~/Views/Shared/InputForm.aspx
~/Views/InputBuilders/InputForm.aspx
~/Views/Home/InputForm.ascx
~/Views/Shared/InputForm.ascx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 input.spark 更改为:
添加到 web.config 在 Spark 中不起作用。您可以使用 _global.spark 代替。
还有一个问题。在稳定的 Spark 中,SparkView
Html
属性的类型为HtmlHelper
,而不是HtmlHelper
。Html.InputForm()
函数仅适用于HtmlHelper
,因此您必须下载 Spark 源代码并使用开发版本,因为它最近已更改。您还可以下载稳定的源并自行更改。以下是一些信息:http://groups .google.com/group/spark-dev/browse_thread/thread/618bd44a94368d22/f7df24e52924f4dc?show_docid=f7df24e52924f4dc
Change input.spark to:
Adding to web.config doesn't work in Spark. You can use _global.spark instead.
There is also another problem. In stable Spark, SparkView
Html
property is of typeHtmlHelper
, notHtmlHelper<TModel>
.Html.InputForm()
function works only forHtmlHelper<TModel>
, so you will have to download Spark source and use development build, because it was changed recently. You can also download stable sources and change it yourself. Here is some info:http://groups.google.com/group/spark-dev/browse_thread/thread/618bd44a94368d22/f7df24e52924f4dc?show_docid=f7df24e52924f4dc
通过设置输入构建器和 Spark 视图引擎,您的方向是正确的。
您可以从 mvccontrib 的源文件中看到,您需要定义 MvcContrib.UI.InputBuilder.Views 命名空间,以便您的视图引用输入构建器 HtmlHelper 扩展。
http://github.com/ mvccontrib/MvcContrib/blob/master/src/MVCContrib/UI/InputBuilder/Views/HtmlExtensions.cs
我编写了输入构建器,但我对 Spark 视图引擎了解不够,不知道为什么它不解析引用输入构建器的扩展方法。
Your on the right track with setting up the input builders and then the spark view engine.
You can see from the source file from mvccontrib that you need this namespace defined MvcContrib.UI.InputBuilder.Views for your view to reference the input builders HtmlHelper Extentions.
http://github.com/mvccontrib/MvcContrib/blob/master/src/MVCContrib/UI/InputBuilder/Views/HtmlExtensions.cs
I wrote the input builders but I do not know enough about the spark view engine to know why it is not resolving the reference to the extention methods for the input builders.