This project is read-only.

Popup form

Almost the same as the Popup, except this is used to render an action that has a form in it's view.
Also this doesn't have the buttons parameter, instead it always makes two buttons:
  • OK - it posts the form (ajax submit)
  • Cancel - closes the popup
(the text of the buttons can be changed)

if the result of the form post is a
  • View (html) - the popup's content is going to be refilled with the returned html (usually when !ModelState.IsValid)
  • Content("ok") - the popup will be closed
  • Json - the popup will be closed and successFunction(retunedJson) called

if you want to enable client side validation for the Popup Form you must include jquery.validate.js and call this in Global.asax.cs Applicaion_Start():
and specify this in MakePopupForm's parameters or change the default Settings
<%=Html.MakePopupForm(..., clientSideValidation: true) %>
//or in your App_Start
Settings.PopupForm.ClientSideValidation = true;


the controller
public class FruitController : Controller 
        public ActionResult Create()
            return View(new FruitInput());

        public ActionResult Create(FruitInput o)
            if (!ModelState.IsValid)
                return View(o);
            return Content("ok");

the create view
@model FruitInput

@Html.EditorFor(o => o.Name)

some view where you have a link that opens a popup to create a fruit
<%=Html.MakePopupForm<FruitController>(o => o.Create()) %>
<%=Html.PopupFormActionLink<FruitController>(o => o.Create()) %>

Last edited May 12, 2011 at 2:47 PM by o, version 2


tyrons Nov 29, 2011 at 6:57 PM 
I had a problem where my View was not being displayed (the dialog window wouldn't show up). After some trial-and-error, I found out that the view being rendered should be a partial view (either by calling it like "return PartialView(new FruitInput());" in the example above, or explicitly declaring "@{ Layout = null; }" on the view.