如何将htmlHelpers添加到Spark virew中 [英] How do you add htmlHelpers into the Spark virew

查看:107
本文介绍了如何将htmlHelpers添加到Spark virew中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Spark视图中使用htmlHelpers,但我不断收到以下错误.

I want to use the htmlHelpers in my spark view but I keep getting the following errors.

错误CS0234:类型或名称空间名称'Mvc'在 命名空间"System.Web"(您是否缺少程序集引用?)

error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

我已将System.Web.Mvc程序集添加到项目中.我还向模块中添加了以下代码(只是为了使其正常工作-我可能需要将此代码添加到引导程序中---尚不知道该怎么做!)

I have added the System.Web.Mvc assembly into the project. I have also added the following code into the module (just for the sake of getting it working - I'll probably need to add this code to the bootstrapper --- not sure how to do that yet!)

var settings = new SparkSettings()
 .SetDebug(true)
 .SetAutomaticEncoding(true)
 .AddAssembly("System.Web")
 .AddAssembly("System.Web.Mvc")
 .AddNamespace("System.Web.Mvc")
 .AddNamespace("System.Web.Mvc.Html");

我还尝试将名称空间添加到_global.spark文件

I also tried adding the namespace to a _global.spark file

请问有人可以确切地告诉我在火花视图中使用htmlHelpers时该怎么做.

Can someone tell me exactly what I must do to use the htmlHelpers in my spark view please.

推荐答案

Nancy的默认Spark基本视图不包含public HtmlHelper Html { get; set; }属性.

The default Spark base view for Nancy doesn't include the public HtmlHelper Html { get; set; } property.

您可以在此处查看默认视图.

为MVC集成实现的Spark视图是在这里,您将看到公开的Html属性,该属性允许您的Spark视图访问它并调用帮助程序.

The Spark view implemented for MVC integration is here, and you'll see the Html property exposed, which allows your Spark view to access it and invoke helpers.

理论上,您可以继承NancySparkView,并在Spark设置中将其指定为基本视图,并在该类中将该属性以及对System.Web.Mvc的引用添加到该类中,然后您的视图应该可以调用假定所有内容均已正确引用,进入帮助器.

In theory, you can inherit from NancySparkView, and specify that as your base view in your Spark settings, and add that property along with references to System.Web.Mvc etc in that class and your views should then be able to call into the helpers assuming everything is referenced correctly.

希望有所帮助
罗布·G

Hope that helps
Rob G

这篇关于如何将htmlHelpers添加到Spark virew中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆