Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am not much more aware in MVC,I want to call a model popup from view or controller after some action perfomed
in MVC 3.Can anyone please give me full sample code.
Posted
Updated 29-Dec-11 21:36pm
v2

It's more js then a mvc asp.net but still it works in MVC 3. I normally using this kind of sample.
JavaScript
<script type="text/javascript">
    $(function () {
        $('#dialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            title: 'hi there',
            modal: true,
            open: function(event, ui) {
                //Load the CreateAlbumPartial action which will return 
                // the partial view _CreateAlbumPartial
                $(this).load("@Url.Action("CreateAlbumPartial")");
            },
            buttons: {
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });

        $('#my-button').click(function () {
            $('#dialog').dialog('open');
        });
    });
</script>
<div id="dialog" title="Create Album" style="overflow: hidden;"></div>
 
Share this answer
 
Comments
Himanshu Yadav 15-Nov-12 5:23am    
Hi Andrew,
It is not working for me
@Url.Action("CreateAlbumPartial")

This line is giving exception
It's more js then a mvc asp.net but still it works in MVC 3. I normally using this kind of sample.

C#
<script type="text/javascript">
    $(function () {
        $('#dialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            title: 'hi there',
            modal: true,
            open: function(event, ui) {
                //Load the CreateAlbumPartial action which will return 
                // the partial view _CreateAlbumPartial
                $(this).load("@Url.Action("CreateAlbumPartial")");
            },
            buttons: {
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });
         
        $('#my-button').click(function () {
            $('#dialog').dialog('open');
        });
    });
</script>
<div id="dialog" title="Create Album" style="overflow: hidden;"></div>
 
Share this answer
 
v3
Comments
Anuja Pawar Indore 27-Jan-12 6:06am    
Added pre tag
XML
<a href="#" onclick="showInfoBar('message')">Info Bar</a> <a href="#" onclick="showPopup('Do you want to delete all appointments?','Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam pulvinar, enim ac hendrerit mattis, lorem mauris vestibulum tellus, nec porttitor diam nunc tempor dui. Aenean orci.')">
                    back to start</a>
            </div>
        </div>
    </div>
    <div id="PopupDiv" class="Popup">
    </div>

    <script type="text/javascript">
        Cufon.replace('.top_nav a');
        Cufon.replace('.media_help h1');
    </script>
    <script type="text/javascript">
        function showPopup(ttle, messg) {
            $.get('@Url.Content("~/Home/InfoBox")', { title: ttle, msg: messg }, setData);
        }
        function showInfoBar(messg) {
            $.get('@Url.Content("~/Home/InfoBar")', { msg: messg }, setData);
        }
        function setData(result) {
            $("#PopupDiv").html(result);
            // viewing the div as block
            $("#PopupDiv").css("display", "block");

        }
    </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900