.NET MVC3剃刀(VB!)扩展不考虑进口的? [英] .NET MVC3 Razor (VB!) Extensions not imported in view?

查看:77
本文介绍了.NET MVC3剃刀(VB!)扩展不考虑进口的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的扩展不是在我vbhtml鉴于进口。我似乎缺少某个东西..大家能否帮助吗?

该module.vb:

 导入System.Runtime.CompilerServices命名空间Areas.Admin.Models.Extensions
<扩展()> _
公用模块InputExtensions
    公共职能SelectHumanGroup(BYVAL帮手作为的HtmlHelper,BYVAL名作为字符串,可选BYVAL了selectedValue的String =,可选BYVAL htmlAttributes作为对象= Nothing)作为MvcHtmlString
        返回helper.DropDownList(姓名,repo.GetGroups(),htmlAttributes)
    结束功能
前端模块
最终命名空间

该view.vbhtml:

  @Imports MySite.Areas.Admin.Models.Extensions
@ModelType MySite.Models.MyViewModel@ code
    ViewData的(标题)=索引
结束code< H2>指数< / H>
@ Html.SelectHumanGroup(测试)


解决方案

我是一个C#的家伙,但这应该是有效的VB以及。
虽然你通过Web.config中添加您的扩展,而不是它是更好的。这样,你就不必添加他们每个视图。
在您的浏览文件夹找到一个web.config。搜索并添加:

 < system.web.webPages.razor>
    <主机factoryType =System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,版本= 3.0.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <页面pageBaseType =System.Web.Mvc.WebViewPage>
      <&命名空间GT;
        <添加命名空间=System.Web.Mvc/>
        <添加命名空间=System.Web.Mvc.Ajax/>
        <添加命名空间=System.Web.Mvc.Html/>
        <添加命名空间=System.Web.Routing/>
        <添加命名空间=MySite.Areas.Admin.Models.Extensions/>
      < /命名空间>
    < /页>
  < /system.web.webPages.razor>

My extensions are not imported in my vbhtml view. I seem to be missing something somewhere.. Can anybody help please?

The module.vb:

Imports System.Runtime.CompilerServices

Namespace Areas.Admin.Models.Extensions
<Extension()> _
Public Module InputExtensions
    Public Function SelectHumanGroup(ByVal helper As HtmlHelper, ByVal name As String, Optional ByVal selectedValue As String = "", Optional ByVal htmlAttributes As Object = Nothing) As MvcHtmlString
        Return helper.DropDownList(name, repo.GetGroups(), htmlAttributes)
    End Function
End Module
End Namespace

The view.vbhtml:

@Imports MySite.Areas.Admin.Models.Extensions
@ModelType MySite.Models.MyViewModel

@Code
    ViewData("Title") = "Index"
End Code

<h2>Index</h2>


@Html.SelectHumanGroup("test")

解决方案

I'm a C# guy, but this should be valid for VB as well. It is better though that you add your extensions via Web.config instead. That way you don't have to add them in every view. Under your Views folder you find a Web.Config. Search for and add:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MySite.Areas.Admin.Models.Extensions" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

这篇关于.NET MVC3剃刀(VB!)扩展不考虑进口的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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