【问题标题】:Using Checkbox submit form in asp.net mvc在 asp.net mvc 中使用 Checkbox 提交表单
【发布时间】:2017-10-07 13:06:24
【问题描述】:

如果选中复选框,我如何更新控制器中的方法?见下图 http://i.stack.imgur.com/5RmbK.jpg

>[HttpPost] 
>public ActionResult Update(int id) 
>{
> //code update status in db
> }

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    试试这个(Razor 语法):

    //for a checkbox 
    @Html.CheckBox("chkName",false, new {onclick="this.form.submit();"})
    
    //if using strongly typed model property
    @Html.CheckBoxFor(model=> model.chkName, new {onclick="this.form.submit();"})
    

    【讨论】:

    • 我已经完成了,谢谢您的回复
      @using (Html.BeginForm("Update", "Admin", new { id = item.ID }, FormMethod.Post)) { @Html.AntiForgeryToken() @Html.CheckBox("CkbStatus", item.Status ? true : false, new { onclick="this.form.submit();"}) }
    • 注意CheckboxCheckboxFor 的使用超过EditorEditorFor。仅仅为 onclick="this.form.submit();" 添加 html 属性是不够的。
    猜你喜欢
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多