它正在寻找的 controllerName 是正确的名称,并且我知道容器中包含具有匹配名称的导出。由于某种原因,它没有找到它。我正在尝试从我放在项目中指定文件夹中的 dll 导入。它总是会尝试返回默认控制器,但找不到 dll 控制器,因为它不在主项目目录中。我知道 controllerFactory 找到了 DLL,但没有正确读取它。
这是我的 CreateController 函数:
Public Function CreateController(requestContext As System.Web.Routing.RequestContext,
controllerName As String) As System.Web.Mvc.IController Implements
System.Web.Mvc.IControllerFactory.CreateController
Dim controller As IController = Nothing
If controllerName IsNot Nothing Then
Dim controllerClassName As String = controllerName & "Controller"
Dim controllers As IEnumerable(Of Lazy(Of IController)) = Me.container.GetExports(Of IController)()
Dim controllerExport As Lazy(Of IController) = controllers _
.Where(Function(c) c.Value.GetType.Name = controllerName) _
.FirstOrDefault()
If export IsNot Nothing Then
controller = export.Value
End If
End If
If controller Is Nothing Then
Return Me.defaultControllerFactory.CreateController(requestContext, controllerName)
End If
Return controller
End Function
如果您需要任何澄清,请告诉我!谢谢!
编辑:返回 Me.defaultControllerFactory.CreateController(requestContext, controllerName) 上的错误消息是 HttpException 未被用户代码处理。找不到控制器路径“CUContractNumberPlugin/ChangeCUNumber”或未实现 IController。
这是它正在谈论的控制器。
<Export(GetType(IController)), ExportMetadata("Name", "CUContractNumberPlugin")> _
Public Class CUContractNumberPluginController
Inherits Controller
<Import(GetType(IHost))>
Private m_hostApp As IHost
Public Function Index() As ActionResult
Return View()
End Function
Function ChangeCUNumber(strCUNumber As String) As ActionResult
m_hostApp.CUNumber = strCUNumber
Return View("Index", m_hostApp)
End Function
End Class
当我将部分视图加载到我的主视图中时,它会被调用。部分观点是这样的:
@Using (Html.BeginForm("ChangeCUNumber", "CUContractNumberPlungin"))
@Html.TextBox("strCUNumber")
End Using