actionResult methon( 类名 变量(m))
{
m.属性名 //得到界面传来的值
}
特别强调:通过对象传值,需保证form表单中的name与类中的属性名称一样
(4)formCollection 传值
格式为:
格式为: public actionResult methon( formCollection 变量(colletion))
{
colletion["name值"] / /得到界面传来的值
}
特别说明:
通过formcollection传值,取值方式:数组+下标(name值)
(5)特别:通过参数获取表单提交的值 格式为在 public actionResult user.UserName + "\n" + "密码:" + user.Password;
}
///
= "父窗口标题") item.Close(); } WinForm时这样操作的: // 遍历并关闭所有子窗口 FormCollection childCollection = Application.OpenForms = "父窗口标题") childCollection[i].Close(); } // 或者也可以这样写: FormCollection childCollection = Application.OpenForms
}
///
通过FormCollection获取表单提交过来的数据 (1)取值方式:数组+下标(name值) public string get(FormCollection col) // 注意:name
3、 使用字符串拼接,然后返回; 注:该方法可以接收到post请求跟get请求; 第二种:FormCollection实例类 1、 在类的实参中使用 FormCollection实例类 声明接收数据的方法
} }); Code [HttpPost] public ActionResult AjaxGetCoupon(FormCollection base.Content("No"); } 若需要返回json则将 $.ajax 中 dataType: "json" 后台: public JsonResult AjaxGetCoupon(FormCollection
= "父窗口标题") item.Close(); } WinForm时这样操作的: // 遍历并关闭所有子窗口 FormCollection childCollection = Application.OpenForms = "父窗口标题") childCollection[i].Close(); } // 或者也可以这样写: FormCollection childCollection = Application.OpenForms
例如,有些开发人员添加参数类型 FormCollection,FormCollection是会传递给 POST 方法的,然后根本不使用此参数: public ActionResult Delete(FormCollection
/// public DbSet<Book> Books { get; set; } }} 加入一个Book控制器 要了解FormCollection请參考:FormCollection data.Single(); return View(); } [HttpPost] public ActionResult Delete(int id, FormCollection c) //事实上这的FormCollection c 换成 int a=5 或者 int a=6 都是能够的。
例如,有些开发人员添加参数类型 FormCollection,FormCollection是会传递给 POST 方法的,然后根本不使用此参数: public ActionResult Delete(FormCollection
下面是我的代码 AllUnSendMail [AcceptVerbs(HttpVerbs.Post)] public ActionResult AllUnSendMail(FormCollection
db.Products.ToList(); return View(products); } [HttpPost] public ActionResult Index(FormCollection formCollection) { // 处理表单提交 return RedirectToAction("Index"); }}Web APIWeb API是构建
验证模型绑定成功与否 使用ModelState.IsValid 获取表单数据 为获得表单数据,使用类型为FormCollection的参数作为操作参数。
return View(); } //新增事件 [HttpPost] public JsonResult Add(FormCollection return View("eidt"); } //编辑事件 [HttpPost] public JsonResult edit(FormCollection
文章修改,新增业务的C#代码 [HttpPost] [ValidateInput(false)] public ActionResult AddNew(FormCollection
现在在现有的代码基础上,我们来看一下,控制器对Bll层的常规调用: 下面给一段简短代码: HomeController => AddUser方法 1 public ActionResult AddUser(FormCollection
return View(stu); } [HttpPost] public ActionResult edit(Students stu, FormCollection
status) => 22 { 23 FormCollection forms = new FormCollection((NameValueCollection)form); 24
false)] [ValidateAntiForgeryToken] [HttpPost] public ActionResult SiteConfig(FormCollection
="请输入密码" value="" /> <input type="submit" value="提交"/> } 控制器代码 public ActionResult TestFrom(FormCollection