本文主要是介绍ASP.NET MVC3中关于httppost提交,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、正常的post提交
Controller
[HttpPost]public string post_test(string str){return "post的字符串是:"+str;}
VIEW
<input id="btn_test" type="button" value="测试" οnclick="post_test();" />
<label id="lbl_show"></label>
<script type="text/javascript">function post_test(){$.post("/test/post_test", { str: "John" }, function (data) {$('#lbl_show').text(data);});}
</script>
这个是正常的post提交
二、使用$.post(),但在url后加参数提交
修改VIEW
<input id="btn_test" type="button" value="测试" οnclick="post_test();" />
<label id="lbl_show"></label>
<script type="text/javascript">function post_test(){$.post("/test/post_test?str=John", function (data) {$('#lbl_show').text(data);});}
</script>

可见这个与get方法提交是没什么区别的。
三、同名参数提交
<input id="btn_test" type="button" value="测试" οnclick="post_test();" />
<label id="lbl_show"></label>
<script type="text/javascript">function post_test(){$.post("/test/post_test?str=Jim", { str: "John" }, function (data) {$('#lbl_show').text(data);});}
</script>

可见url后提交的参数被忽略了。
四、参数名不同
[HttpPost]public string post_test(string str1,string str2){return "post的字符串是:"+str1+","+str2;}
<input id="btn_test" type="button" value="测试" οnclick="post_test();" />
<label id="lbl_show"></label>
<script type="text/javascript">function post_test(){$.post("/test/post_test?str1=Jim", { str2: "John" }, function (data) {$('#lbl_show').text(data);});}
</script>
结果:
可见str1,str2的值都传入了,str1使用的是get方式,str2使用的是post方式
这篇关于ASP.NET MVC3中关于httppost提交的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!