2

On my layout view I have

@Html.MakePopup(new MakePopupParams
    {
        Action = "Create",
        Title = "New Job Offer",
        Modal = true,
        Resizable = false,
        Height = 450,
        Width = 750,
        Position = "center"
    })

    <div style="padding-left: 10px">
        @Html.PopupActionLink(new PopupActionLinkParams
        {
            Action = "Create",
            Text = "Add new Job Offer",
            HtmlAttributes = new { @class = "btn btn-success btn-small" }
        })
    </div>

This renders a button that creates a dialog where a view (Create) is rendered. Everything works fine.

The problem is when I submit the form, if the ModelState is not valid I want to return the view, with the model, and the validation messages. But if I return the view like this

// there is something wrong with the data values
            return View(newOffer);

The browser shows the view as a whole.

How can I return the view to the dialog that is opened?

tereško
  • 58,060
  • 25
  • 98
  • 150
Miguel Teixeira
  • 783
  • 1
  • 10
  • 29
  • you're using a popup, but you want to use the PopupForm, you can download the Awesome v 1.9 (the one that you're using) Demo from codeplex https://awesome.codeplex.com/releases/view/66067 – Omu Nov 21 '14 at 22:20
  • In case of popup use ajax submit rather than the normal submission of the form. – Kundan Singh Chouhan Dec 07 '14 at 17:17

2 Answers2

0

If the problem is that your view is getting the site's layout surrounding it, you should be able to avoid that by specifying that it's a partial view:

return PartialView(newOffer);

Update

You need to make the button or form in your dialog be picked up by a JavaScript handler that does the form submission via AJAX and replaces the dialog contents with what comes back from the server. Here's one example of how you might do that.

Community
  • 1
  • 1
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
  • It as the same result. The view is rendered as the "main page" instead of being returned to the dialog – Miguel Teixeira Nov 21 '14 at 16:29
  • @MiguelTeixeira: Sorry, I thought your problem was that the returned "whole page" was being displayed inside your dialog. I've updated my answer. Bear in mind that this is a simplistic answer that will have other caveats. For example, how does the javascript handler decide whether to update the dialog or change the whole page? You'll need to decide how you want to deal with the complicated parts yourself. – StriplingWarrior Nov 21 '14 at 20:34
0

You're using the Popup helper which only creates a popup, the PopupForm creates a popup that handles form submits, also adds an Ok and Cancel button

http://awesome.codeplex.com/wikipage?title=PopupForm


so in your case the browser was showing the view as a whole because the submit wasn't handled, you should use the PopupForm instead

Omu
  • 69,856
  • 92
  • 277
  • 407