Window MVC 3 Razor PopUp

I need to open a new popup with the click of a button in a view. A new window should be redirected to a specific action method in a specific controller. I also need to provide attributes for the size of the new popup. I tried the following code:

<input type="button" name = "ClickMe" Value="ClickMe" onclick= "javascript:window.open('/Home/Create/','Customer Search',height='window.screen.height - 100', width='200',left='window.screen.width - 250' ,top='10',status='no',toobar='no',resizable='yes',scrollbars='yes')"/>

When a button is pressed, nothing happens. I get the following Javascript error:

Line: 19
Char: 1
Error: Invalid argument.
Code: 0

When I check the ViewSource of the displayed HTML, I find that the line will be the one that displays the button. I am using Windows Vista with IE 7. I am working on MVC 3 with Razor Engine in VS 2010

+5
source share
3 answers

Respect html. Respect javascript. Follow the structure you are writing on, which has made two major changes (validation and ajax) from its second version to the third, in order to apply the new, modern principle - Unobtrusive Javascript . You could fix this error in less time spent asking the question here if you followed this principle (using syntax highlighting vs javascript).

    <input type="button" id="ClickMe" name = "ClickMe" Value="ClickMe" />
...
    <script type="text/javascript">
            $(function () {
                $('#ClickMe').click(function () {
                   window.open('/Home/Create/', 'CustomerSearch', 'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
                });
            });
    </script>

And as I discovered, this is a problem with the space in the window name in IE - "Client Search". If you delete this space - "CustomerSearch", it will also start working in IE

+13
source

HTML ' onclick. ( ):

<input type="button"
       name="ClickMe"
       value="ClickMe"
       onclick="javascript:window.open('/Home/Create/',
                                       'Customer Search',
                                       'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');"/>

:

  • window.open() - JavaScript .
  • '
  • toobartoolbar.

, :

var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

strWindowName
, . , <a> <form>. . strWindowName . ()

+5
<script type="text/javascript">
    //script for loading value to division
    $(function () {
        $('form').submit(function () {
            $.ajax({
                url: this.action, //you can redirect to your specific controller here..
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    $('#popUp').html(result);
                }
            });
            return false;
        });
    });
</script>

<script type="text/javascript">
    //Script for pop up dialog.
    $(function () {
        $('form').submit(function () {
            $("#popUp").dialog({
                modal: true,
                resizable: false
            });
        });
    });
</script>

<div id="popUp" >
</div>
0

All Articles