Formcollection取值

xiaoxiao2021-02-28  119

1.前台需要form表单

eg:

<form action="/Home/Add" id="myform" method="post" style="border:1px solid #ff0000"> <table> <tr> <td>姓名:</td> <td><input type="text" id="name" name="name" placeholder="请输入姓名" value="" /></td> </tr> <tr> <td>年龄:</td> <td> <select id="age" name="age"> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> </select> </td> </tr> <tr> <td><input type="submit" id="btn_add_1" value="添加" /></td> </tr> </table> </form> 注意:必须要name属性,不然没有值

2.后台

public ActionResult Add_1(FormCollection form) { string name =form["name"]; int age = Convert.ToInt32(form["age"]); return View(); } 有view就返回view

转载请注明原文地址: https://www.6miu.com/read-44740.html

最新回复(0)