Submit Button on Razor View doesn't call Action Result - MVC

273 views Asked by At

I have an issue with my submit button not calling the actionresult. I have set the breakpoint in the action result itself so i know that the actionResult is not even being called. Thank you in advance for your guidance.

View:

@model CCQAS.WebApp.Areas.Credentialing.Models.TransferCustodyViewModel
@using CCQAS.API.Model.Enums
@{var PersonId = ViewBag.SessionPersonId;}
@{ViewBag.Title = "Transfer Custody ";
ViewBag.HelpText = "When this record transfer becomes effective, responsibility for updating and maintaining this credentials record will be transferred to the gaining UIC";}

@using (Html.BeginForm("CreateCustodyTransfer", "TransferCustody", FormMethod.Post, new { @id = "transfer-custody-form", @role = "form" }))
{
@Html.AntiForgeryToken()
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">
                    Transfer Custody for @Html.DisplayFor(model => model.LastNameCommaFirstName)
                    @Html.Partial("_SectionHelp", (string)ViewBag.HelpText)
                </h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-4 col-md-4">
                        <div class="form-group require">
                            @Html.LabelFor(model => model.UIC, "Transfer Record To")
                            <div class="input-group focus" tabindex="0" id="uic_txt">
                                @Html.EditorFor(model => model.UIC, "Uic", new { serviceLevel = true })
                            </div>
                            @Html.ValidationMessageFor(model => model.UIC)
                        </div>
                    </div>

                    <div class="col-sm-4 col-md-4">
                        <div class="form-group require">
                            @Html.LabelFor(model => model.ReasonId)
                            @Html.EnumDropDownListFor(model => model.ReasonId, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.ReasonId)
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-4">
                        <div class="form-group require" hidden="hidden" id="divOtherReason">
                            @Html.LabelFor(model => model.OtherReasonTxt)
                            @Html.TextBoxFor(model => model.OtherReasonTxt, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.OtherReasonTxt)
                        </div>
                    </div>
                </div>
                <div class="row">

                    <div class="col-sm-4 col-md-4">
                        <div class="form-group require">
                            @Html.LabelFor(model => model.EffectiveDateString)
                            @Html.TextBoxFor(model => model.EffectiveDateString, new { @class = "form-control", @disabled = "disabled" })
                            @Html.ValidationMessageFor(model => model.EffectiveDate)
                        </div>
                    </div>

                </div>

            </div>
            <div class="panel-footer text-center">
               <input type="submit" value="Submit" data-loading-text="Submitting..." class="btn btn-primary" autocomplete="off" id="submitButton" />
                <button type="button" onclick="goBack()" class="btn btn-default">Cancel</button>
            </div>
        </div>
    </div>
</div>
}

@section scripts{
<script>
    $(function () {

        var uic = $("#UIC");
        var reasonId = $("#ReasonId");
        var otherReason = $("#OtherReasonTxt");

        $('#submitButton').click(function (event) {
            if ((uic.val() != "" && reasonId.val() != "" && reasonId.val() != 99999) || (uic.val() != "" && reasonId.val() != "" && otherReason.val() != "")) {
                if (!confirm("Are you sure you want to transfer custody?")) {
                    resetButtonState();
                    return false;
                }
            }

        });
    });
    function goBack() {

        window.location.href = document.referrer;
    }
    $('#ReasonId').change(function () {
        toggleOtherReason();
    });

    //Other Reason fields will only display if "Other" is selected from the ReasonId drop down list
    function toggleOtherReason() {
        var reasonId = $("#ReasonId").val();

        if (reasonId == 99999) {
            $("#divOtherReason").show();
        }
        else {
            $("#divOtherReason").hide();
        }
    }
</script>
}

Controller:

[HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult CreateCustodyTransfer(TransferCustodyViewModel viewModel)
    {
        string serviceCode = null;
        var result = mtfService.GetMtfId(viewModel.UIC, serviceCode, null);
        viewModel.MTFId = (long)result;

        var model = new CredCustody();
        {
            model.UIC = viewModel.UIC;
            model.ReasonId = viewModel.ReasonId;
            model.OtherReasonTxt = viewModel.OtherReasonTxt;
            model.UserMtfId = CurrentUser.PrimaryMtfId;
            model.UserText = CurrentUser.Name;
            model.CredProviderId = this.CredProvider.CredProviderId;
            model.AuditUserId = CurrentUser.UserId;
            model.MTFId = viewModel.MTFId;
        };

        long credCustodyId = this.credCustodyService.CreateCredCustody(model);
        SetPageMessage(PageMessageType.Success, String.Format("Custody Transferred"));
        return RedirectToAction("SearchResults", "ProviderSearch");
    }
0

There are 0 answers