JavaScript按钮是't转到HttpPost方法

JavaScript button isn't going to HttpPost Method

本文关键字:转到 HttpPost 方法 按钮 JavaScript      更新时间:2023-09-26

JS:

<script type="text/javascript">
    $('#dialog').dialog({
        autoOpen: false,
        width: 600,
        modal: true,
        buttons: {
            "Yes": function () {
                $("#DSCreateForm").submit(); // part that isn't working correctly
            },
            "Cancel": function () { $(this).dialog("close"); }
        }
    });
    var hobbsValue = $('#HobbsValue').val();
    alert(hobbsValue);
    if (hobbsValue == null || hobbsValue.length == 0) {
        $('.btnSubmitDS').on("click", function (e) {
            e.preventDefault();
            $(function () {
                $('#dialog').dialog('open')
            });
        });
    }
</script>

CSHTML:

@using (Html.BeginForm("Create", "DailySummaries", FormMethod.Post, new { id = "DSCreateForm" }))
<div class="form-group">
        @Html.LabelFor(model => model.Hobbs, "HOBBS:", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Hobbs, new { htmlAttributes = new { id = "HobbsValue", @class = "form-control hobbs-textbox", @placeholder = "xxxx.x" } })
            @Html.ValidationMessageFor(model => model.Hobbs, "", new { @class = "text-danger" })
        </div>
    </div>

控制器:

[HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "...")] DailySummary dailySummary)
    {

在上面的代码中,当选择"是"按钮时,它正在提交,但当我调试时,它不会转到控制器的HttpPost方法。我该如何做到这一点?

我大胆假设您还没有设置method="post"在你的表格上?

编辑:现在您已经提供了表单创建代码,我可以看到情况并非如此。