使用面积不能加载鉴于asp.net MVC 3 vb.net [英] Cannot load view in area in asp.net mvc 3 using vb.net

查看:180
本文介绍了使用面积不能加载鉴于asp.net MVC 3 vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有VS 2010,.NET 4.0和MVC 3的最新版本,我必须用vb.net时使用asp.net mvc的3个区域的一个问题。

I have the latest versions of VS 2010, .NET 4.0 and MVC 3 and I have a problem using areas in asp.net mvc 3 when using vb.net.

我做到以下几点:


  1. 创建一个新的Visual Basic asp.net MVC 3项目。选择剃刀的查看恩金,并呼吁该项目TestApp。

  2. 创建一个名为Test的新领域,这将是在文件夹中:/区/测试

  3. 添加名为PageController.vb一个新的空控制器/区/测试/控制器/\".

  4. 添加一个新的文件夹/区/测试/查看/称为页。

  5. 添加一个新的空观/区/测试/查看/页名为Index.vbhtml。

  6. 运行项目。

  7. 手动键入URL的http://本地主机:XYZ /测试/页在浏览器中,其中xyz是由VS生成的自动添加端口号

在第7步我得到的消息资源无法找到。

At step 7 I get the message "The resource cannot be found".

如果我使用C#做同样的事情,然后我会得到正确的页面,它会显示为预期的单词索引。

If I do exactly the same thing using c# then I will get to the correct page and it will show the word "Index" as expected.

这是一个错误,还是我失去了一些东西?我一直在扫描网络上几个小时试图解决这一点,但我得到noware。

Is this a bug, or am I missing something? I have been scanning the web for hours trying to solve this but I am getting noware.

这是自动生成的文件TestAreaRegistration.vb
命名空间TestApp.Areas.Test
    公共类TestAreaRegistration
        继承AreaRegistration

This is the automatically created TestAreaRegistration.vb file Namespace TestApp.Areas.Test Public Class TestAreaRegistration Inherits AreaRegistration

    Public Overrides ReadOnly Property AreaName() As String
        Get
            Return "Test"
        End Get
    End Property

    Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext)
        context.MapRoute( _
            "Test_default", _
           "Test/{controller}/{action}/{id}", _
            New With {.action = "Index", .id = UrlParameter.Optional} _
        )
    End Sub
End Class

结束名称空间

这是自动生成的文件Global.ascx:
注意:有关启用IIS6 IIS7或经典模式的指令,
'访问 http://go.microsoft.com/?LinkId=9394802

And this is the automatically created Global.ascx file: ' Note: For instructions on enabling IIS6 or IIS7 classic mode, ' visit http://go.microsoft.com/?LinkId=9394802

公共类MvcApplication
    继承System.Web.HttpApplication

Public Class MvcApplication Inherits System.Web.HttpApplication

Shared Sub RegisterGlobalFilters(ByVal filters As GlobalFilterCollection)
    filters.Add(New HandleErrorAttribute())
End Sub

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

    ' MapRoute takes the following parameters, in order:
    ' (1) Route name
    ' (2) URL with parameters
    ' (3) Parameter defaults
    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
    )

End Sub

Sub Application_Start()
    AreaRegistration.RegisterAllAreas()

    RegisterGlobalFilters(GlobalFilters.Filters)
    RegisterRoutes(RouteTable.Routes)
End Sub

末级

这些是你会得到什么,如果你repete步骤1-7和使用C#一样的(唯一的区别是,你会得到C#code等于上述vb.net code)。

These are identical with what you get if you repete steps 1-7 and use c# (only difference is that you will get c# code that is equal to above vb.net code).

我repete:如果我在C#中它的工作步骤1-7,但它不会在vb.net工作!什么是错的?

I repete: If I do the steps 1-7 in C# it works, but it will not work in vb.net! What is wrong?

推荐答案

的问题是,你的控制器是不是在默认的控制器命名空间。你需要自己手动引用控制器命名空间。有这种过载。试试这个:

The problem is that your controllers are not in the default controller namespace. You will need to manually reference the controller namespaces yourself. There is an overload for this. Try this:

Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext)
        context.MapRoute( _
            "Test_default", _
           "Test/{controller}/{action}/{id}", _
            New With {.action = "Index", .id = UrlParameter.Optional}, _
            New With {"MyDefaultNamespace/Areas/Test/Controllers"} _
        )
End Sub

默认区域配置文件实际上并没有引用该地区的控制器命名空间。这是一个不幸的监督。所以,除非你在全球复制旧的控制器到新的文件夹(保留旧的命名空间),你会在第一次就得到一个错误。引用正确的命名空间将解决这个问题。

The default area config file doesn't actually reference the area's controller namespace. This is an unfortunate oversight. So, unless you copy your old controllers over in to the new folders (and retain the old namespace), you'll get an error on the first go. referencing the correct namespaces will fix this issue.

编辑:

另外,你没有提到有关创建你的页面的操作什么......这是一个错字,还是来一个默认控制器?

Also, you didn't mention anything about creating an action for your page... is this a typo, or did the controller come with one by default?

这篇关于使用面积不能加载鉴于asp.net MVC 3 vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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