0

I have a primary form defined and nicely laid out, it does what it needs to do...

@{ Html.BeginForm(); }
@Html.ValidationSummary(false)
@Html.AntiForgeryToken()
@Html.EditorFor(model => model)
<h2>Properties</h2>
<hr />
@* I want to put some stuff here... *@
<br class="space" />
<div class="clearfix">>
    <button type="submit" data-bind="click: save">
        Save
    </button>
</div>
@{ Html.EndForm(); }

Now, then. This model (or ViewModel, rather) has an IList<PropertyViewModel> attached to it.

A PropertyViewModel has its own set of validations. They are pretty simple for now, but there is a chance that later there will be more complicated uses for this setup.

I am using KnockoutJS for my viewModel consistency. Though I suppose it is fairly irrelevent. I want to display a second form in a jQuery UI Dialog and return the result, essentially..

<script type="text/javascript">
    var viewModel = {
        name: ko.observable(),
        description: ko.observable(),
        properties: ko.observableArray(),

        save: function () {
            alert(ko.toJSON(viewModel));
        },

        includeProperty: function () {
            $("#dialog").dialog({
                width: 500,
                closeText: '',
                resizable: true,
                buttons: {
                    'Submit': function () {
                        $(this).dialog('close');
                        callback( @* I want the new data to get sent back *@ );
                    },
                    'Cancel': function () {
                        $(this).dialog('close');
                        return false;
                    }
                }
            });
        }
    };
    function callback(value) {
        alert(ko.toJSON(value)); // (I will push the new property to the viewmodel here)
    }
    ko.applyBindings(viewModel);
</script>

However, I am not really sure how to actually put the EditorTemplate into the dialog, moreover I am not sure how to get the data back out of it.

1 Answer 1

1

I don't completely understand your question, but from what I understood what you are trying to do is pass data to the dialog and retrieve data from the dialog. If that is the case then this may be useful:

http://api.jquery.com/jQuery.data/

Here is detailed example on how to use:

Passing data to a jQuery UI Dialog

Sign up to request clarification or add additional context in comments.

5 Comments

No, that is not really what I am trying to do... or if it is, these examples are extremely cryptic. I do not understand any of this. I need to display a second form inside of a dialog, do validation on it, and return the result back to the original form.
Actually, this might work. I could wrap the form in a partial view and load it into the dialog, and return its data... I'll experiment a bit, thank you. This isn't quite the answer I was looking for, but I'll see if I can take a different approach using it.
This did not solve my problem, but it did open up some interesting solutions to other problems.
@Ciel - I would suggest then maybe rephrasing your question so we can help
Actually, this did inevitably solve it because it showed me some things about dialogs I did not previously understand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.