它正在寻找的控制器名称是正确的名称,我知道容器中的导出具有匹配的名称。由于某种原因,它找不到它。我试图从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