This helper is used to display a popup, you can add buttons to it and specify js functions for each button.
The content of the popup can be filled with the result of an action, or defined in the view.

@Html.MakePopup("Hey") // init popup for Action Hey of current controller

@Html.PopupActionLink("Hey") // generate the link

example with buttons and strongly typed helpers:
<script type="text/javascript">
        function sayHi() { alert('hi'); }

@(Html.MakePopup<PopupDemoController>(o => o.Info(),
buttons: new Dictionary<string, string>
                    {"say hi","sayHi"}, 
                    {"say how are you", "function(){ alert('how are you'); }"},

@(Html.PopupActionLink<PopupDemoController>(o => o.Info(), "link text"))

calling an action with parameters

considering there is this action:
public ActionResult Do(int a, string b) { ... }

it can be open in a popup like this:
<%=Html.MakePopup("Do", parameters:new string[]{"a","b"}) %>
<%=Html.PopupActionLink("Do", parameters: new object[]{1, "hi" }) %> // a = 1, b = "hi"

or with strongly typed helpers like this:
<%=Html.MakePopup<HomeController>(o => o.Do(0, null)) %> // values given here to the Do Action aren't important, they are just required by the lambda
<%=Html.PopupActionLink<HomeController>(o => o.Do(1,"hi")) %>

sometimes you might do something like this:
<%=Html.MakePopup<HomeController>(o => o.Do(0, null)) %>

<% foreach(var item in Model) { %>
<%=Html.PopupActionLink<HomeController>(o => o.Do(item.Number, item.SomeString)) %>
<% } %>

Last edited May 12, 2011 at 12:58 PM by o, version 3


No comments yet.