tags:

views:

434

answers:

2

Hi,

I am using ASP .NET to display a JQuery dialog that has a few input fields. I now need these fields to submitted to an action method like how a normal HTML submit button would work on an ASP .NET MVC application. How do I accomplish this?

  • This is my form data:

All form fields are required.

<%Html.BeginForm("AddUser", "User"); %>
<fieldset>
 <label for="name">Name</label>
 <input type="text" name="name" id="name" />
 <label for="email">Email</label>
 <input type="text" name="email" id="email" value="" />
 <label for="password">Password</label>
 <input type="password" name="password" id="password" value="" />
</fieldset>
<%Html.EndForm(); %>

"

  • And this is my script:
    $(function() {
        $("#dialog").dialog({
            bgiframe: true,
            height: 400,
            width: 600,
            modal: true,
            buttons: {
                'Create user account': function() {
                   $(this).dialog('close');
                },
                Cancel: function() {
                    $(this).dialog('close');
                }
            }
        });
    });
+5  A: 

Add a line to your code that submits the form:

$(function() { 
    $("#dialog").dialog({ 
        bgiframe: true, 
        height: 400, 
        width: 600, 
        modal: true, 
        buttons: 
        { 
            'Create user account': function() {
                 $('#yourDialogFormID').submit(); // add this line
                 $(this).dialog('close'); 
             },
             Cancel: function() { 
                 $(this).dialog('close'); 
             }
       }
    });
 });

You can set the ID by giving the Html.BeginForm() method an argument for htmlAttributes (type object if I remember the structure correctly - look for it in the overload methods in IntelliSense).

Tomas Lycken
+2  A: 

You can harvest the data from your form and post it using jQuery.post

$.post("someform.aspx", { name: $("#name").val(), email: $("#email").val() } );
TreeUK