在控制器'#######'上找不到公共操作方法'undefined'

时间:2013-08-28 07:12:57

标签: asp.net-mvc undefined

Maday, 我在db中记录了这个错误任何想法或线索来修复这个间歇性的asp.net mvc异常。 感谢

Unhandled System.Web.HttpException (0x80004005): A public action method 'undefined' was not found on controller '#######'.
   at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)    at System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

2 个答案:

答案 0 :(得分:1)

我不能肯定地说,但我怀疑这是在JavaScript中构造URL的结果,其中没有定义变量。

类似的东西:

var action
var url = '/myContoller/' + action

这将导致请求:

  

/ myContoller /未定义

预期的URL可以用于甚至不打算成为MVC路由的内容。它可能是一个图像或其他东西。

var imageUrl
var url = '/folder/' + imageUrl
  

/ MyFolder文件/未定义

MVC将尝试对其进行路由,具体取决于路由的配置方式。

您的日志中是否有关于请求来自何处的信息?

更新1:

如果您希望MVC忽略对您网站特定区域的所有请求(例如图像目录),您可以执行以下操作:

routes.IgnoreRoute("images/{*pathinfo}");

答案 1 :(得分:0)


根据@ Dan的helpful answer,我已经看到了修复图片网址路由问题的可行方法:

<小时/> 所以,因为我在RouteConfig.cs中有404错误的“全能”路线:

// for 404-error page routing
routes.MapRoute(
    name: "Error",
    url: "{*url}",
    defaults: new { controller = "Error", action = "PageNotFound" }
);


...... MVC奇怪地将我通过Razor @foreach语句加载的图像解释为URL:

// this is triggering the weird problem, dunno why:
@foreach (string image in this.Model.ImageArray)
{
    <img src="@this.Url.Content(image)" title="foobar" alt="@image" />
}


Exception类型为HttpException,生成的Exception消息为:

  

在控制器'MyWebsite.Controllers.HomeController'上找不到公共操作方法'[object HTMLImageElement]'



routes.IgnoreRoute("MyImageFolderPath/{*pathinfo}");置于我的RegisterRoutes RouteConfig.cs方法的顶部而不是可以解决此问题,但是这样做了:

routes.IgnoreRoute("[object HTMLImageElement]");


它似乎仍然是hackish,并且由于我处理404错误的执行不力......

您可以通过在RouteConfig.cs中以及Application_Error中的Global.asax.cs方法中填充断点来验证它是否有效(如果您还在那里处理HttpException错误)。