当前位置:   MFC > 正文

在asp.net mvc 3 razor中识别html助手的问题

asp.net-mvc,asp.net-mvc-3,html,mvc,webview,ajax,DevBox,在线流程图,编程,编程问答,程序员,开发者工具,开发工具,json解析,二维码生成,unix时间戳,在线开发工具,前端开发工具,开发人员工具,站长工具

这就是我的Html助手的样子:

namespace WebApp.WebUI
{
    public static class HtmlExtensions
    {

            public static MvcHtmlString GenerateCaptcha(this HtmlHelper helper, string theme)
            {
                string publicKey = ConfigurationManager.AppSettings["CaptchaKey_Public"];
                string privateKey = ConfigurationManager.AppSettings["CaptchaKey_Private"];
                var captchaControl = new Recaptcha.RecaptchaControl
                        {
                            ID = "recaptcha",
                            Theme = theme,
                            PublicKey = publicKey,
                            PrivateKey = privateKey
                        };

                var htmlWriter = new HtmlTextWriter(new StringWriter());

                captchaControl.RenderControl(htmlWriter);

                return new MvcHtmlString(htmlWriter.InnerWriter.ToString());
            }

     }
}

我试过在这个视图中使用它:

    @{
        ViewBag.Title = "Register";
    }
    @model WebApp.WebUI.ViewModel.RegisterModel

    @using (Html.BeginForm("Register", "Auth", FormMethod.Post, new { Id = "ERForm" }))
    {
        @Html.GenerateCaptcha("clean")   
    }

它给了我这个错误:

CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'GenerateCaptcha' and no extension method 'GenerateCaptcha' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

我究竟做错了什么.我的命名空间是正确的.它没有出现在intellisense中@Html



1> Darin Dimitr..:

你可以添加:

@using WebApp.WebUI

在你的剃刀视图的顶部.

如果你想在许多不同的视图中重用这个帮助器,以避免每次添加using子句,你可以将它添加到文件的部分~/Views/web.config:


    
    
        
            
            
            
            
            
        
    

执行此操作后,请确保重新编译并重新打开智能感知的Razor视图,以便有时间进行搜索.

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/blog/MFC/detail/22325
推荐阅读
相关标签
  

闽ICP备14008679号