tags:

views:

313

answers:

6

My Dialog Box is an jquery Dialog Box, my popup use <%Html.RenderPartial("MyUC")%> to call an usercontroll for Markup for a Dialog Box. How to the controller can call the value in Dialog Box

A: 

If you have a vaule in a TextBox for example there are 2 ways for you to return valuse from the page.

In the Controller request the value specifically.

[AcceptVerbs(HttpVerbs.Post)]
public SomeViewController(string stringValueFromTextBoxOnPartialView){}

The other way to do it is to request the whole form as a FormCollection. This was you can add a fiew input types to your page and you'll only need one object in you're controller.

[AcceptVerbs(HttpVerbs.Post)]
public SomeViewController(FormCollection form){}

More detailed descriptions can be found at http://www.asp.net/learn/mvc/tutorial-33-cs.aspx

Webmonger
Sorry please help me understand your problem better. You have a form in a jQuery Dialog box that you want to post data back to a controller? Do you want the page to post back to happen asynchronously using Ajax or synchronously using browser postback? If you want to use Ajax then check out the docs at docs.jquery.com/Ajax and add the ajax code to this function in your code "Save": function() { } That will enable you to send the data to the controller and nicely close the DialogBox without refreshing the page.
Webmonger
A: 

uhm i try your way but it wrong.because i use a jquery dialog to show data, now i want to get data to controller,but in controller not catch data on dialog. how i catch data in dialog???

A: 

Your dialog must contain element, which action url points to YorController/YourAction. Put some with name attribute inside . Then submit the form when dialog "Ok" button is pressed - you'll have passed value in controller.

Roman
A: 

If your dialog has a form field that wasn't there at the start, i.e. jQuery made it, the you can have your controller ask for it like this

this.Request["jQueryDialogElement"]

or

this.Url.RequestContext.HttpContext.Request["jQueryDialogElement"]

You can put a break point in and see if it is in the QueryString, or Form member of the Request object if you don't know.

Mark Dickinson
If you aren't already, consider using Firefox and Firebug to find out more about what you jQuery is putting into your UI.
Mark Dickinson
A: 

It's my dialog code

    $(function() {
        $("#dialog").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 300,
            modal: true,
            buttons: {
                "Save": function() {
                    $("#edit").submit();
                    $('#dialog p').empty();
                }, 
                Cancel: function() {
                    $(this).dialog('close');
                    $('#dialog p').empty();                        
                }
            },                
            close: function() {
                allFields.val('').removeClass('ui-state-error');                   
            }
        });

        submitHandler: function(form) {
            $('#dialog p').append('Click \'OK\' to confirm Edit of <b>$' + $("#Item").val());
            $('#dialog').dialog('open');
        }

        $("input[name=Edit]").click(function() {

            var hd = $(this).next(); //will give u hidden div

            $("#dialog input[id=ItemId]").val(hd.children("#ItemId").val());
            //$("#dialog input[id=CatId]").val(hd.children("#CatId").val());
            $("#dialog select > option[id=" + hd.children("#CatId").val() + "]").attr("selected", "selected");
            $("#dialog input[id=UnitId]").val(hd.children("#UnitId").val());
            $("#dialog input[id=SaleOffId]").val(hd.children("#SaleOffId").val());
            $("#dialog input[id=ItemCode]").val(hd.children("#ItemCode").val());
            $("#dialog input[id=ItemName]").val(hd.children("#ItemName").val());
            $("#dialog input[id=UnitCost]").val(hd.children("#UnitCost").val());
            $("#dialog input[id=QuantityRemaining]").val(hd.children("#QuantityRemaining").val());
            $("#dialog form").attr("post", "/Item/EditTest/" + hd.children("#ItemId").val(),'json');

            alert("/Item/EditTest/" + hd.children("#ItemId").val());
            $('#dialog').dialog('open');
        })
    .hover(
        function() {
            $(this).addClass("ui-state-hover");
        },
        function() {
            $(this).removeClass("ui-state-hover");
        }
    ).mousedown(function() {
        $(this).addClass("ui-state-active");
    })
    .mouseup(function() {
        $(this).removeClass("ui-state-active");
    });
    });

You can show me i where i wrong? Where I can fix?

Best regards,

Vicky

Maybe not "$("#edit").submit();" but "$('form').submit();"?
Roman
A: 

And This is div contain dialog

  <% Html.BeginForm("EditTest", "Item"); %>
           <table>
             <tr>
               <td><b>ItemId</b></td>
               <td><input id="ItemId" name="ItemId" type="text" disabled="disabled" /></td>
             </tr>
               <tr>
               <td><b>CatId</b></td>
               <td><input id="CatId" name="CatId" type="text" />
                   <%--<%= Html.DropDownList("CatId", ViewData["AllCategory"] as SelectList)%>--%></td>
             </tr>
               <tr>
               <td><b>SaleOffId</b></td>
               <td><input id="SaleOffId" name="SaleOffId" type="text"/></td>
             </tr>
               <tr>
               <td><b>UnitId</b></td>
               <td><input id="UnitId" name="UnitId" type="text" /></td>
             </tr>
               <tr>
               <td><b>ItemCode</b></td>
               <td><input id="ItemCode" name="ItemCode" type="text" /></td>
             </tr>
               <tr>
               <td><b>ItemName</b></td>
               <td><input id="ItemName" name="ItemName" type="text" /></td>
             </tr>
               <tr>
               <td><b>UnitCost</b></td>
               <td><input id="UnitCost" name="UnitCost" type="text"/></td>
             </tr>
               <tr>
               <td><b>QuantityRemaining</b></td>
               <td><input id="QuantityRemaining" name="QuantityRemaining" type="text"/></td>
             </tr>
             <tr>
               <td><input type="submit" id="Save" name="Save" value="Save" /></td>
               <td><input type="submit" id="Cancel" name="Cancel" value="Cancle" onclick="back(-1);" /></td>
             </tr>
           </table>