Popup Form Refresh/Redirect Problem after successful httpPost

Aug 4, 2011 at 8:52 PM


First of all, I really like the controls provided by this project! Now, I am relatively new to using the form popup and have a problem with refresh/redirect and closing of the pop-up in my MVC 3 Razor project after httpPost is complete. I searched the discussion board and could not find anyone having similar problems so please help.

Currently my pop up form comes up fine and is able to update the database assuming Model is valid (which is the case). The problem is that if after httpPost I redirect with RedirectToAction, that view is being reloaded inside the dialog box. I tried to go around it by using "return View()" (which failed due to that view being connected to viewmodel which is empty after successful post) and by using "return Content("Ok")" like in the SimpleDemo but both did not work (the Ok messaged replaced the form but the dialog box remained).

What I want is a way to either close dialog and reload to the same page using some script or RedirecttoAction from the controller to the same view which will trigger page reload in a full browser as opposed to loading it inside the dialog.

Below is my code, please let me know if you need more information and I am going to gladly provide it

My Controller Action:


public ActionResult AddExternalReference(int id)
			ViewBag.ExternalReferencesTypes = new SelectList(db.ExternalReferenceTypes, "Id", "Name");

			ExternalReference externalreference = new ExternalReference();
			externalreference.Id = id;

			CreateExternalViewModel externalreferenceviewmodel = new CreateExternalViewModel()
				References = externalreference

			return View(externalreferenceviewmodel);
		public ActionResult AddExternalReference(CreateExternalViewModel externalreferenceviewmodel, int clientid)
			var client = db.Clients.FirstOrDefault(z => z.Id == clientid);

			if (ModelState.IsValid)
				//return View();
				return RedirectToAction("Index", "Main", new { id = clientid });
				ViewBag.ExternalReferencesTypes = new SelectList(db.ExternalReferenceTypes, "Id", "Name");
				return View(new { model = externalreferenceviewmodel, clientid });




namespace GoGoLegal.Areas.Clients.Models
	public class CreateExternalViewModel
		public ExternalReference References { get; set; }


In my View

@(Html.MakePopupForm<GoGoLegal.Areas.Clients.Controllers.MainController>(o => o.AddExternalReference(Model.Id), okText: "Add External Reference", modal: true, title: "Add External Reference", successFunction: "killdialog"))

 @(Html.PopupFormActionLink<GoGoLegal.Areas.Clients.Controllers.MainController>(o => o.AddExternalReference(Model.Id), "Add External Reference", new { @class = "button" }))

There is also EditorTemplate:

@model GoGoLegal.Models.ExternalReference   @Html.HiddenFor(model => model.Id)
<div class="editor-label"> External Reference</div><div class="editor-field">

@Html.TextBoxFor(model => model.Value, new { @style = "width: 110px;", @watermark = "Number" })

@Html.DropDownListFor(model => model.ExtRefTypeID, ViewBag.ExternalReferencesTypes as SelectList, new { @style = "width: 150px;" }) 

 <div style="clear: right;"> </div>

 @Html.ValidationMessageFor(model => model.Value)

 @Html.ValidationMessageFor(model => model.ExtRefTypeID)</div>

Aug 5, 2011 at 7:43 AM

instead of 

return RedirectToAction("Index", "Main", new { id = clientid });

return a Json(new {id = clientid}))
and in the successFunction do the redirect