我不确定我问的是否可能。我有一个表格,上面有一个复选框列表和按钮。用户从列表中进行选择,然后单击该按钮并将其写入数据库。现在我想添加第二个按钮,它将执行与选择不同的操作。我如何将第二个按钮链接到另一个动作?
当前代码:
@using (Html.BeginForm("RemoveFromAvailable", "GroupPlayManager", new { id = Model.Id, slug = Model.Slug, innerid = Model.GroupPlayManagerId }, FormMethod.Post, null))
{
<div class="hMarginBottom15">
<input type="hidden" class="groupPlay-id" name="GroupPlayId" value="@Model.GroupPlayInput.Id" />
<input type="hidden" name="GroupPlayManagerId" value="@Model.GroupPlayManagerId" />
<input type="hidden" name="GroupPlayDateTime" value="@Model.GroupPlayInput.GroupPlayDate" />
<button name="RemoveFromAvailable" id="unavailableButton" class="btn btn-danger" disabled="disabled">Remove</button>
</div>
@Html.EditorFor(
m => m.AvailablePlayers,
"BootstrapHorizontalCheckboxList",
new
{
data = Model.AvailablePlayersDates.Select(tm => new SelectListItem
{
Text = tm.Name,
Value = tm.Id,
}).ToList(),
chunksize = 1,
isRequired = true,
displaylabel = false,
cssClass = "col-md-12"
})
}
答案 0 :(得分:1)
为您的按钮命名,然后相应地分支您的行动。例如:
<button type="submit" name="_Save">Save</button>
<button type="submit" name="_SomethingElse">Something Else</button>
然后,在你的行动中:
if (Request["_Save"] != null))
{
// save
}
else if (Request["_SomethingElse"] != null))
{
// do something else
}
只有当用户点击该特定按钮时才会出现该密钥。