0
votes

I am using JavaScript to submit the popup dialog, but it's not submitting.

here is my view, I have checked the javascript, it is firing up but the $("form").submit() statement is not doing anything and the next statement is executed.

@{ 
    ViewBag.Title = "Add Comment";
    Layout = "~/Views/Shared/Popup.cshtml"; 
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#SaveComment").click(function (e) {
            e.preventDefault();
            $("#form").submit();
            parent.HidePopup(true);
        });
    });
    </script>

@using (Html.BeginForm("CreateComment", "OnlineInventory", FormMethod.Post, new { id = "form"}))
{
    @Html.Hidden("OccupantInventoryRoomId", Model.OccupantInventoryRoomId)
    @Html.Hidden("OccupantInventoryItemId", Model.OccupantInventoryItemId)
    @Html.HiddenFor(m => m.AllocationId)
    @Html.HiddenFor(m => m.Status)

    @Html.TextAreaFor(m => m.Comment, new { Class="CommentTextBox" })
    <div class="Navigation">
        <input type="button" value="Cancel" onclick="parent.HidePopup(false)" />
        <input id="SaveComment" type="button" value="Save" class="InputButton"/>
    </div>
}

this is my controller

  public class OnlineInventoryController : Controller
    {
        [HttpPost]
        public ActionResult CreateComment(AddNewCommentModel model, int? allocationId)
        {
            User user = this.userProvider.GetByUserName(System.Web.HttpContext.Current.User.Identity.Name);

            if (!this.userProvider.IsAllowed(9, user.KxId))
            {
                return this.RedirectToAction("Index", "Inspections");
            }

            try
            {
                OccupantInventoryComment commentToSave = new OccupantInventoryComment
                {
                    Comment = model.Comment,
                    CommentDateTime = DateTime.Now,
                    CreatedByUserId = user.KxId,
                    OccupantInventoryRoomId = model.OccupantInventoryRoomId,
                    OccupantInventoryItemId = model.OccupantInventoryItemId,
                };
                ViewBag.OccupantInventoryRoomId = model.OccupantInventoryRoomId;
                ViewBag.OccupantInventoryItemId = model.OccupantInventoryItemId;
                this.occupantInventoryCommentProvider.Save(commentToSave);
            }
            catch (Exception ex)
            {
                this._audit.Add(Product.KxRoomCheckerBackOffice, Severity.Error, ActivityType.Create, new StackTrace().GetFrame(0).GetMethod().Name, string.Empty, string.Empty, ex);
            }

            return this.RedirectToAction(model.Status.ToString(), new InventoryModel { AllocationId = model.AllocationId, Updated = true });
        }
}