Search code examples
asp.net-mvc-3windowactionlink

How do I close a window after clicking a button?


I am using MVC 3 and I have a button that the user presses to either update some records or to not update some records. I am trying to close the tab after the user presses the No, thank you button. After doing some research all that I have been able to find on this subject is to close a window using jQuery or javascript. I was hoping that there is a way to close the window in the actionLink. I have included the button code below and feel free to ask any questions you might have as I will be checking back often. If you need any other code I would be happy to supply that as well. Thanks for your help!

<div class="message dialog" title="Changes Saved">
            You have successfully saved your changes.<br/>Would you like to update the other versions of this Project?
            <br />
            @Html.ActionLink("Yes, Update Projects", "UpdateProject", "Project", new { id = Model.IAMP_PK }, new { @class = "button2" })
            @Html.ActionLink("No, Thank you", null, null, new { @class = "button2" })
            </div>

Solution

  • You cannot close the browser from server-side. And I am not sure why you want that when client-side solution is pretty simple.

    Change the button to:

    @Html.ActionLink("No, Thank you", null, null, new { @class = "button2", id="close" })
    

    Then do

    $("#close").click(function() { window.close(); });