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

[Solved] How to get a form working with content via .ajaxRequest

4 Answers 128 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.
Kori
Top achievements
Rank 2
Kori asked on 01 Mar 2011, 06:03 PM
Hey,

So, what I'm trying to do - is load the window using content being loaded via the client side, like this (this is from the main view, where the window is located, and the client script that opens it):
<button id='FormButton'>Open Form</button>
@(Html.Telerik().Window()
    .Name("Window")
    .Modal(true)
    .Resizable(resize => resize.Enabled(true))
    .Buttons(buttons => buttons.Refresh().Maximize().Close())
    .Draggable(true)
    .Visible(false)
    .Effects(effects => effects.Toggle().Opacity())
    )
 
@if ((!string.IsNullOrEmpty(ViewBag.FirstName)) || (!string.IsNullOrEmpty(ViewBag.LastName)))
{
    <div>
        You Entered:
        <table>
            <tr>
                <td>First Name:</td>
                <td>@ViewBag.FirstName</td>
            </tr>
            <tr>
                <td>Last Name:</td>
                <td>@ViewBag.LastName</td>
            </tr>
        </table>
    </div>
}
<script type="text/javascript">
    function PageLoad() {
 
        $("#FormButton").click(function (e) {
            OpenWindow("/TestApp/Window/FormTest");
        });
 
        $('t-button').live('mouseenter', $.telerik.buttonHover)
                     .live('mouseleave', $.telerik.buttonLeave);
    }
 
    function OpenWindow(path) {
        var wnd = $('#Window').data('tWindow');
        if (wnd != null) {
            wnd.ajaxRequest(path);
            wnd.center().open();
        }
    }
 
    function CloseWindow() {
        var wnd = $('#Window').data('tWindow');
        if (wnd != null) {
            wnd.close();
        }
    }
</script>

And I have my form view, which looks like this:
@using (Html.BeginForm("FormTest", "Window", FormMethod.Post, new { id = "feedback-form" }))
{
    <fieldset>
        <legend>FormTestViewModel</legend>
 
        <div class="editor-label">
            @Html.LabelFor(model => model.FirstName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstName)
        </div>
 
        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
        </div>
 
        <p>
            <button type="submit" class="t-button">Create</button>
            <button type="button" class="t-button">Close</button>
        </p>
    </fieldset>
}

Here's the controller for the form:
public partial class WindowController : Controller
    {
 
        public ActionResult FormTest()
        {
            return View();
        }
 
        [HttpPost]
        public ActionResult FormTest(FormTestViewModel model)
        {
            if (ModelState.IsValid)
            {
                ViewBag.FirstName = model.FirstName;
                ViewBag.LastName = model.LastName;
            }
            return View();
        }
    }

But what's happening, is that if I follow the code on the sample - the page redirects to the form view which isn't what I would be expecting. On the sample, the modal window closes and the information entered into the form appears on the page. So, what's wrong here? Why doesn't this work?

-- Kori

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Mar 2011, 10:08 AM
Hi Kori,

Please clarify this "the page redirects to the form view which isn't what I would be expecting". Which page redirects to the form view and when does this happen? Could you attach your project so we can check it out?

Regards,
Atanas Korchev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Kori
Top achievements
Rank 2
answered on 02 Mar 2011, 03:14 PM
Atanas,

Okay, I've submitted that support ticket with project for you.

-- Kori
0
Kori
Top achievements
Rank 2
answered on 21 Mar 2011, 08:55 PM
Okay, so I've cleared up the original issue with support. However, this isn't quite what I need. In our existing app, we use RadWindow and all the window code is self contained.

What doesn't work, and what I'm looking to solve, for the MVC version - is that I want the [HttpPost] method to be located in the window controller and specifically not on the main page controller (which was my fault in the thread above). In my app, we're using forms that are dynamically generated based on items in a database as well as some specifically crafted ones, and I can't fill my "App" controller with post methods for all of them.

Any ideas? Maybe one that can "pass along" to the correct WindowController method? Would that work?

-- Kori
0
Kori
Top achievements
Rank 2
answered on 21 Mar 2011, 09:01 PM
Okay, so I've cleared up the original issue with support. However, this isn't quite what I need. In our existing app, we use RadWindow and all the window code is self contained.

What doesn't work, and what I'm looking to solve, for the MVC version - is that I want the [HttpPost] method to be located in the window controller and specifically not on the main page controller (which was my fault in the thread above). In my app, we're using forms that are dynamically generated based on items in a database as well as some specifically crafted ones, and I can't fill my "App" controller with post methods for all of them.

Any ideas? Maybe one that can "pass along" to the correct WindowController method? Would that work?

-- Kori
Tags
Window
Asked by
Kori
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Kori
Top achievements
Rank 2
Share this question
or