本文导读:在ASP.NET MVC框架中,为了限制某个action只接受HttpPost的请求,对于HttpGet的请求则提示404找不到页面,可以在action的方法前面加上[HttpPost]属性。下面介绍Action前HttpPost的作用

一、Action前HttpPost实例

 

mvc中Action前HttpPost的作用mvc中Action前HttpPost的作用
[HttpPost]  
mvc中Action前HttpPost的作用
public string post_test(string str)  
{ mvc中Action前HttpPost的作用 return "post的字符串是:"+str; mvc中Action前HttpPost的作用} mvc中Action前HttpPost的作用

 

脚本调用

 

mvc中Action前HttpPost的作用mvc中Action前HttpPost的作用
function post_test()  
{ { mvc中Action前HttpPost的作用 $('#lbl_show').text(data); mvc中Action前HttpPost的作用 }); mvc中Action前HttpPost的作用} mvc中Action前HttpPost的作用
 
 
或者
 
 
mvc中Action前HttpPost的作用{ mvc中Action前HttpPost的作用 type: "POST", mvc中Action前HttpPost的作用 url: "/test/post_test", mvc中Action前HttpPost的作用 data: "str='" + John+ "'", { mvc中Action前HttpPost的作用 $('#lbl_show').text(data);  mvc中Action前HttpPost的作用 } mvc中Action前HttpPost的作用 }); mvc中Action前HttpPost的作用

 

二、Action前HttpPost 的作用

限制action只接受HttpPost的请求,对于HttpGet的请求则提示404找不到页面。

如果Action前即没有 [HttpPost],也没有 [HttpGet] ,则两种方式的请求都接收。

 

三、Post方式提交数据后,Controller中寻找Action的相应机制

1、查找有没有[HttpPost]标注的Register Action,如果有,则执行,如果没有,则2

2、查找有没有没有任何[HttpPost]或者[HttpGet]标记的Register Action,如果有,则执行,如果没有,则3

3、返回“The Resource can't be found"的异常信息

 

 

 

 

 

一、Action前HttpPost 的作用

限制action只接受HttpPost的请求,对于HttpGet的请求则提示404找不到页面。

如果Action前即没有 [HttpPost],也没有 [HttpGet] ,则两种方式的请求都接收。

 

二、Post方式提交数据后,Controller中寻找Action的相应机制

1、查找有没有[HttpPost]标注的Register Action,如果有,则执行,如果没有,则2

2、查找有没有没有任何[HttpPost]或者[HttpGet]标记的Register Action,如果有,则执行,如果没有,则3

3、返回“The Resource can't be found"的异常信息

 

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-02-15
  • 2022-02-22
  • 2021-08-14
相关资源
相似解决方案