asp.net中 mvc的post方式提交也其他普通的提交没有什么大区别,只不过多了自己点特色


页面html表单类似这样:
<form action="http://test.com/edit" method="post">
id:<input name="id" type="text" />
<input type="submit" value="submit">
</form>

mvc代码有两个方式

1.在路由中配置url路径,类似http://test.com/edit
然后在controller类的action方法中

[HttpPost]
public ActionResult Edit()
{
      tring temp = Request.Form["id"];//html表单中的控件的name值
......

}

2.第二种方式,是在路由配置详细的路径
路由中类似这样"edit/{id}/{name}"
把参数定义在路由映射中,参数的名称就是表单中控件名称
这样就可以在controller类中的action方法中这样写
[HttpPost]
        public ActionResult Edit(string id,string name)
        {
            //string temp = Request.Form["id"];
            return View();
        }
方法的参数就是html表单中的参数

本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

相关文章:

  • 2021-11-13
  • 2022-12-23
  • 2021-08-19
  • 2021-11-19
  • 2022-12-23
  • 2021-08-07
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-09-30
  • 2021-11-26
  • 2021-10-10
  • 2021-11-02
相关资源
相似解决方案