在控制器中建立一个UserEditor方法 并建立视图

<body>
    <form action="UserEditor" method="post">
        <div>
            <table>
                <tr>
                    <td>ID:</td>
                    <td class="textid" name="id">@Model.Id</td>
                </tr>
                <tr>
                    <td>姓名:</td>
                    <td><input type="text" name="name" value="@Model.Name" class="name" /></td>
                </tr>
                <tr>
                    <td>地址:</td>
                    <td><input type="text" name="address" value="@Model.Address" class="address" /></td>
                </tr>
                <tr>
                    <td>出生日期:</td>
                    <td><input type="text" name="birthday" value="@Model.Birthday" class="birthday" /></td>
                </tr>
                <tr>
                    <td>邮箱:</td>
                    <td><input type="text" name="email" value="@Model.Mail" class="email" /></td>
                </tr>
            </table>
            <input type="submit" value="提交" class="submmmt"/>
        </div>
    </form>
</body>

创建另一个UserEditor同名方法

public ActionResult UserEditor()

    {
        int id = Convert.ToInt32(Request["id"]);
        UserManager user = new UserManager();
        User seluser = user.UserSelect(id);   
        return View(seluser);
    }

    //标记为Post方式请求,改方法就只能接受post方法请求
    [HttpPost]
    public ActionResult UserEditor(FormCollection from)//参数为FormCollection类型,表示是获取提交保单所有的数据
    {
        UserManager user = new UserManager();
        int i =Convert.ToInt32( from["id"]);
        string n = from["name"];
        string a = from["address"];
        string b = from["birthday"];
        string e = from["email"];
        bool bl = false;
        bl = user.UserUpdada(i, n, a, b, e);
        User seluser = user.UserSelect(i);
        return View(seluser);
    }

点击提交

获取form表单中的值

最后修改:2020 年 12 月 08 日 09 : 52 AM
如果觉得我的文章对你有用,请随意赞赏