cshtml中的按钮功能

时间:2014-07-31 18:04:33

标签: sql razor

我有这个按钮代码

<button type="submit" class="btn btn-primary" value="approvebutton" name="button">Approve</button>
<button type="submit" class="btn btn-danger" value="rejectbutton" name="button">Reject</button>
<button type="submit" class="btn btn-danger" value="@row.appointment_id" name="hiddenbutton" style="display: none"></button>

获取它的代码是

if(IsPost){
    var appointment_id = Request.Form["hiddenbutton"];

    if(Request.Form["button"] == "approvebutton"){
        //approve the appointment
        var approveappointmentcommand = "UPDATE appointment set appointment_approve = 1 WHERE appointment_id = @0";//1 for approved        
        var approveappointmentdata = db.Execute(approveappointmentcommand, appointment_id);
    }

    if(Request.Form["button"] == "rejectbutton"){
        //reject the appointment
        var rejectappointmentcommand = "DELETE FROM appointment WHERE appointment_id = @0";
        var rejectappointmentdata = db.Execute(rejectappointmentcommand, appointment_id);
    }
}

我希望删除/批准能够对付项目的特定ID。但事实上并没有真正发生。我的意思是没有执行任何查询。

任何帮助?

2 个答案:

答案 0 :(得分:0)

我认为问题是你隐藏的按钮;用隐藏字段替换它:

<input type="hidden" name="hiddenbutton" value="@row.appointment_id" />

答案 1 :(得分:0)

<button type="submit" class="btn btn-primary" value="approvebutton" name="button">Approve</button>
<button type="submit" class="btn btn-danger" value="rejectbutton" name="button">Reject</button>
<button type="submit" class="btn btn-danger" value="@row.appointment_id" name="hiddenbutton" style="display: none"></button>

当您提交表单时,请求数据将如下所示

hiddenbutton={row.appointment_id}&button=approve&button=reject

Request.Form["hiddenbutton"] = {row.appointment_id}
Request.Form["button"] = "approve,reject"

不使用javascript

您需要2个表格或1个单选按钮