This is a migrated thread and some comments may be shown as answers.

[Solved] Submitting a Window?

11 Answers 441 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Prakash
Top achievements
Rank 1
Prakash asked on 05 Oct 2010, 10:02 PM
Is it possible to submit a window to a Controller Action? I am trying to show some dropdown items within Window. Upon user selecting an item, there should be a 'Save' button which should save the user preference and close the Window. What is the best way to achieve it?

11 Answers, 1 is accepted

Sort by
0
Derek Hunziker
Top achievements
Rank 1
answered on 07 Oct 2010, 12:04 AM
I was able to achieve this by pointing the window's content setting at another view. For example:

.Content(() =>
       { %>
    <iframe src="<%= Url.Action("AnotherAction") %>" style="width: 100%; height: 100%;" frameborder="0"></iframe>
    <% })

You can handle all of your logic in the separate view, including validation, form elements and a submit button. To close the window, you can call a javascript function in the calling view by using parent.MyJavaScriptFunction() from within the window itself.
0
Paul Hoeffer
Top achievements
Rank 1
answered on 09 Dec 2010, 01:08 AM
Is this the only way?  It seems clunky and I'm wondering why the control doesn't work the way it should. 
0
Alex Gyoshev
Telerik team
answered on 09 Dec 2010, 10:24 AM

If you have the following window declaration:

<%  Html.Telerik().Window()
        .Name("Window")
        .Title("Submit feedback")
        .Content(() => {%>
            <% using (Html.BeginForm("popupform", "window", FormMethod.Post, new { id = "feedback-form" }))
               { %>
                    <label for="name">Name:</label>
                    <%= Html.TextBox("name") %>
                    <label for="email">E-mail:</label>
                    <%= Html.TextBox("email") %>
                    <div class="form-actions">
                        <button type="submit" class="t-button t-state-default">Submit feedback!</button>
                    </div>
            <% } %>
        <%})
        .Width(400)
        .Draggable(true)
        .Modal(true)
        .Visible(false)
        .Render();
%>
 
You can attach a JavaScript handler to the submit button, which serializes the form and posts it through AJAX:

$('#feedback-form').submit(function(e) {
    var data = $(this).serialize();
    $.post(this.action, data, function(){
        $('#feedback-form').closest('.t-window').data('tWindow').close();
    });
    e.preventDefault();
});

This way, you'll have ajax submission and clean HTML.

All the best,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul Hoeffer
Top achievements
Rank 1
answered on 09 Dec 2010, 07:43 PM
How is this different from simply using

window.ajaxRequest(url);


in JS?
0
T. Tsonev
Telerik team
answered on 10 Dec 2010, 08:23 AM
Hi Paul,

The window.ajaxRequest function will submit a GET request to the specified URL. It will not use POST to submit the form to the server.

I hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Williams
Top achievements
Rank 1
answered on 12 Dec 2010, 10:04 PM
Why wouldn't you just use an Ajax form instead of doing all of the manual work to hook the submit button and serialize the data?

<% using (Ajax.BeginForm(new AjaxOptions {UpdateTargetId = "SaveResult" }))
{
}
%>
0
Alex Gyoshev
Telerik team
answered on 13 Dec 2010, 08:51 AM
Hello Chris,

Whatever works. Personally, I'd stick to the $.post because it doesn't require two more JS files to be loaded (Microsoft.Ajax.js and MicrosoftMvc.Ajax.js). If they are already loaded, the AJAX form will require less code to get going.

Regards,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cory Deppen
Top achievements
Rank 1
answered on 18 Jan 2011, 12:40 AM
What would the 'popupform' action method return in this case?
0
Chad DeHart
Top achievements
Rank 1
answered on 08 Sep 2011, 07:31 PM
As Cory Deppen asked, does anyone know what the proper return would be for the popupform action method?  It works with a RedirectToAction, but it doesn't seem right.
0
Alex Gyoshev
Telerik team
answered on 09 Sep 2011, 11:41 AM
Depends on whether you want to communicate with the server, i.e. whether you want the controller to return a result that you'll interpret on the client. I assume that you mean the scenario where you don't want any content returned (otherwise you can return a PartialView / JsonResult). When you want no content to be returned, the proper way to do it is to return a 204 HTTP status code (No Content). In MVC3, there's a HttpStatusCodeResult that you can return -- see this StackOverflow thread for more info.

Best wishes,
Alex Gyoshev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Robert
Top achievements
Rank 1
answered on 20 Apr 2012, 12:11 AM
Hi Alex,

This was very helpful. I have a slightly different scenario in that after the form is submitted, I need to refresh a "Detail" grid in a Master/Detail setup. I was going to use Ajax.BeginForm until I came across your advice here and was planning on using this function:
function onSuccess(e) {
    var grid = $("#Components_" + e).data("tGrid");
    grid.ajaxRequest();
};

How would I refresh a a specific detail grid if I am using the attach/serialize method?

Thanks

Tags
Window
Asked by
Prakash
Top achievements
Rank 1
Answers by
Derek Hunziker
Top achievements
Rank 1
Paul Hoeffer
Top achievements
Rank 1
Alex Gyoshev
Telerik team
T. Tsonev
Telerik team
Chris Williams
Top achievements
Rank 1
Cory Deppen
Top achievements
Rank 1
Chad DeHart
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or