本文介绍了关于[HttpPost]动作过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在控制器的索引操作上放置 [HttpPost] 过滤器时。我收到错误无法找到资源。

请任何机构解释我为什么会这样。



When I place [HttpPost] filter on Index action of my controller. I get error The resource cannot be found.
Please any body explain me why is this happen.

public class BooksController : Controller
   {
       public ActionResult Index()
       {
           return View();
       }



以上代码在我写localhost时很容易运行:1530 /在浏览器中预订。

但是当我在它上面写[HttpPost](如下面的代码所示)它显示错误。




above code run easily when i write localhost:1530/Book in browser.
But when I write [HttpPost] on it (as below code) it shows error.

public class BooksController : Controller
    {
        [HttpPost]
        public ActionResult Index()
        {
            return View();
        }





我的 routeconfig 代码低于



my routeconfig code is below

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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







解释我为什么会这样。




Explain me why is this happen.

推荐答案


这篇关于关于[HttpPost]动作过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:02
查看更多