Ajax 常用获取数据方式(post和get)

  控制器层

        //获取表单元素的三种方式:(提交方式为post)
        //第一种:FormCollection form
        public ActionResult formAction(FormCollection form)
        {
            string name = form["txtName"];
            string sex = form["cboSex"];
            string address = form["txtAddress"];
            return Content(name + "&" + sex + "&" + address);//Content(string)返回字符串
            //FormCollection用来在controller中获取页面表单元素的数据。它是表单元素的集合,包括元素。
        }

        //获取表单元素的三种方式:(提交方式为post)
        //第二种:Request.Form["txtName"];  txtName为表单元素中name属性的值
        public ActionResult formAction1()
        {
            string name = Request.Form["txtName"];
            string sex = Request.Form["cboSex"];
            string address = Request.Form["txtAddress"];
            return Content(name + "&" + sex + "&" + address);
        }

        //获取表单元素的三种方式:(提交方式get)
        //第三种:get提交
        public ActionResult getAction(string txtName,string cboSex,string txtAddress)
        {
            string name = txtName;
            string sex = cboSex;
            string address = txtAddress;
            return Content(name + "&" + sex + "&" + address);//Content(string)返回字符串。
        }

  界面层


@{
    Layout = null;
}





    
    form
    
    
    


    

 

 

 

 

 

你可能感兴趣的:(前端,Ajax)