0

I have a modal dialog in which I have a text field I want to pass a value to controller.

Pop-up dialog is as follows

@using (Html.BeginForm("Index", "QC", FormMethod.Post, new { id = "qcForm" }))
{
...
    <div id="dialog-form" title="Add Feedback">
        <p class="validateTips">Please enter Feedback :</p>
        @Html.TextBoxFor(m => m.RejectionReason, new { @class = "required" })
    </div>
...
}

Submits as follows

$(document).ready(function () {
    $('#btnRejectAll').click(function(event) {
        event.preventDefault();
        $("#dialog-form").dialog("open");
    });

    $("#dialog-form").dialog({
        autoOpen: false,
        height: 300,
        width: 420,
        modal: true,
        resizable: false,
        buttons: {
            "Submit": function () {
                $("#qcForm").submit();
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        },
        close: function () {
            $(this).dialog("close");
        }
    });
});

If I have the textbox just in my form and not in dialog it submits fine. But in the dialog it comes in as NULL in the controller.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
StevieB
  • 6,263
  • 38
  • 108
  • 193
  • I guess you are missing this line - **@model YourWeb.Models.YourClass** above this line - **@using (Html.BeginForm(...))** in your pop-up dialog and is it in Partial view ?? – Krishnraj Rana Jun 26 '14 at 15:22
  • Oh sorry I have that already in the view, and no its not a partial view – StevieB Jun 26 '14 at 15:25
  • I would check the html in a browser after the pop-up occurs. It's very possible that the dialog is cloned outside the form or some other change occurs that prevent the textbox in your form from being populated. – Erik Philips Jun 26 '14 at 15:32
  • @StevieB - Try this code - **$.post(form.attr("action"), JSON.stringify($(form).serializeObject()), function () { // Close your dialog...; });** in - "Submit": section.. – Krishnraj Rana Jun 26 '14 at 15:35
  • Hey Krishnrai where abouts does that go – StevieB Jun 26 '14 at 15:37
  • Hey Erik, its just jquery modal dialog, it does seem to put the div outside my main form which is a bit weird – StevieB Jun 26 '14 at 15:37
  • it should go to your Index method of QC controller... and also check this link - [http://nickstips.wordpress.com/2011/08/11/asp-net-mvc-ajax-dialog-form-using-jquery-ui/](http://nickstips.wordpress.com/2011/08/11/asp-net-mvc-ajax-dialog-form-using-jquery-ui/) and also this - [http://stackoverflow.com/questions/6443337/jquery-mvc3-submitting-a-partial-view-form-within-a-modal-dialog](http://stackoverflow.com/questions/6443337/jquery-mvc3-submitting-a-partial-view-form-within-a-modal-dialog) – Krishnraj Rana Jun 26 '14 at 16:02

0 Answers0