关于[HttpPost]动作过滤器 [英] About [HttpPost] action filter

查看:158
本文介绍了关于[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.

推荐答案




我找到你传递id参数的空值。



检查一下,如果您需要进一步的帮助,请将路由配置文件内容和操作过滤器代码段发布给我
Hi
It looks for me that you are passing null value for the id parameter.

Check this out and if you need further assistance, post me the routing config file contents and the action filter code segments


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆