How do you add htmlHelpers into the Spark virew

半腔热情 提交于 2019-12-24 01:54:59

问题


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

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

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");

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

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


回答1:


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

You can see the default view here.

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.

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.

Hope that helps
Rob G




回答2:


I'm not a Nancy expert, but I'm sure the type of the View is different than that of Asp.Net MVC. So, theoretically, you shouldn't be able to use MVC helpers, since they require the Html property on the View.



来源:https://stackoverflow.com/questions/11782458/how-do-you-add-htmlhelpers-into-the-spark-virew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!