-1

如果当前对象有孩子,我有一个动作应该提示用户。用户也应该能够选择是否更新孩子。我该如何处理用户对此提示的响应?

<tr>
            <td><button type="submit" class="button">Save</button></td>
            @if (Model.OrganizationHasChildren)
            {
                <td>@Html.ActionLink("Save", "AleMasterData", null, new {@class = "button",onclick = "return confirm('Do you want to apply the ALE Indicator change to the sub-clients also?');" })</td>
            }
            else
            {
                <td>@Html.ActionLink("Save", "AleMasterData", null, new {@class = "button"})</td>
            }
        </tr>
4

1 回答 1

1

最简单的选择,用一个额外的布尔值构建一个 ViewModel,这将在标记中表示为:

@Html.HiddenFor(model => model.ChoiceBool) 

并用一点 Jquery 更新它

    function submitForm() {
        var l_choice = confirm('Do you want to apply the ALE Indicator change to the sub-clients also?');
        $('#ChoiceBool').val(l_choice);              
        $('#SaveForm').submit();
    }

当然有

        @if (Model.OrganizationHasChildren)
        {
            <td>@Html.ActionLink("Save", "AleMasterData", null, new {@class = "button", onclick = "submitForm();" })</td>
        }
        else
        {
            <td>@Html.ActionLink("Save", "AleMasterData", null, new {@class = "button"})</td>
        }

然后您应该能够在操作服务器端检索它

或者您可以使用选择值更新相同 JS 方法中的 URL,并使用这样的原型在服务器端检索它

 public ActionResult Save(bool choice, ViewModel viewModel)

但是对于相同的结果来说这更复杂,如果你想尝试第二个选项,会进行更多研究

于 2013-09-09T15:33:57.353 回答