应用程序不读取MVC3中的动作结果方法

时间:2011-10-08 14:22:49

标签: forms asp.net-mvc-3 http controller

我们正在使用MVC3,我们正在尝试在名为UserSesionManager的Controller中创建一个方法。从

调用此方法
@using (Html.BeginForm("GetStatTypesDistribution", "UserSesionManager", FormMethod.Post, new { enctype = "multipart/form-data" }))

在UserSesionmanager控制器中,我们有:

[HttpPost]
        public ActionResult GetStatTypesDistribution(FormCollection form)

但是,当我们调用它时,我们会收到此错误:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /UserSesionManager/GetStatTypesDistribution

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

此外,当我添加断点时,它表示源代码与原始版本不同。我按照右键单击位置的说明操作,但错误仍然存​​在。

为什么会发生这种情况,我们如何解决这个问题?

非常感谢!

2 个答案:

答案 0 :(得分:1)

确保控制器的名称为UserSesionManagerController,而不仅仅是UserSesionManager

public class UserSesionManagerController: Controller
{
    ...

    [HttpPost]
    public ActionResult GetStatTypesDistribution(FormCollection form)
    {
        ...
    }
}

还要确保global.asax中有默认路由:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

答案 1 :(得分:1)

重建您的解决方案。停止用于调试的Web服务器,并检查以确保您使用的是内置Web服务器(Cassini),它不在系统托盘中运行。

在Visual Studio中调试F5。如果仍然出现错误,则从调试菜单加载模块窗口,然后加载模块。找到列出的代码,看看它是从哪里加载的。

如果还是个问题,请从临时的asp.net文件夹中删除apps文件夹并再次尝试调试,但模块窗口应该提供一些信息。