Ext.Net and MVC - Close Window based on condition

  1. #1

    Ext.Net and MVC - Close Window based on condition

    I am using Ext.Net in an MVC application. On my main page, I have a Window that launches a partial view based on a condition -

    @if(Model.ShowScreen)
    {        
        @(x.Window()
            .ID("myWindow")
            .Title("My Title")
            .Icon(Icon.Application)
            .Height(550)
            .Width(500)       
            .Modal(true)
            .Content(c => @Html.Partial("MyPartial", Model))
        )        
    }
    else
    {
        // Not sure what goes here    
    
    }
    I expect that if the showscreen bool in the model is true, then the Window will show. If the bool is false, the window should not appear. I am able to render the view once and the window shows up as expected. However, if I change the bool to false and attempt to re-render the page, the window is still appearing.
    I have stepped through and verify that the correct bool value is being passed and it goes into the else part of the statement, but the window is still rendered (or is still remaining in the DOM from the previous rendering).

    Here is my controller action for the partial -

    [HttpPost]
            public ActionResult MyPartial(MyViewModel model)
            {
                return RedirectToAction("Index", new { @id = model.myId });            
            }
    Does anyone know what I would have to do in order to get the Window to not render / be closed?

    I have tried using javascript / jquery to close the window, but have not had any luck.

    If more code is needed, let me know and I can post accordingly.

    Thanks
  2. #2
    Hi @czuroski,

    Welcome to the Ext.NET forums!

    attempt to re-render the page
    Please clarify how do you do that?

    I have tried using javascript / jquery to close the window, but have not had any luck.
    Please try:
    App.myWindow.hide();
    or
    App.myWindow.close();
    As for JQuery, it is unlikely you need it if you use Ext.NET.
  3. #3
    In order to re-render the page, I have my Window call into a controller action that calls RedirectToAction back to the main view. I had hoped this would re-render the entire view and therefore not show the ext window. But that doesn't work.

    I have tried App.MyWindow.Close(); and App.MyWindow.Hide();, but that didn't seem to work. What is the proper syntax for that - do I have to put it in a script tag, or behind an @ sign for razor to recognize it?

    Thanksc
  4. #4
    Quote Originally Posted by czuroski View Post
    I have tried App.MyWindow.Close(); and App.MyWindow.Hide();, but that didn't seem to work. What is the proper syntax for that - do I have to put it in a script tag, or behind an @ sign for razor to recognize it?
    It is JavaScript. You can use it like that:
    @Html.X().Button().Text("Hide Window").Handler("App.myWindow.hide();")
    Please note that JavaScript is case-sensitive.
  5. #5
    Thanks, and that certainly makes sense.
    However, I don't want to have a button. I have an if/else in my view and the window should be rendered/shown based on a bool in the model. So if the bool is false, then the window should be hidden without the need for a button push.

    Can this be done?
  6. #6
    Ok, please clarify what do you mean by "Window call"?
    Quote Originally Posted by czuroski View Post
    In order to re-render the page, I have my Window call into a controller action
    Also where is Model.ShowScreen being changed?

    A full test case could clarify the things.
  7. #7
    The window call is this -

    @if(Model.ShowScreen)
    {        
        @(x.Window()
            .ID("myWindow")
            .Title("My Title")
            .Icon(Icon.Application)
            .Height(550)
            .Width(500)       
            .Modal(true)
            .Content(c => @Html.Partial("MyPartial", Model))
        )        
    }
    else
    {
        // Not sure what goes here    
     
    }
    I change the value of the showscreen bool in the controller and then pass it back to the view. That is where I am calling Return View() in the controller action. In my first post, I have a controller method that is a redirecttoaction which sends data to the index Actionresult in the controller. Based on the data passed in, the ShowScreen is changed to false, but when the view renders, the Window (myWindow) is still visible. I would like to put something in the else part of the if statement that would automatically trigger myWindow to hide.
    Unfortunately, I don't have my code in front of me, so I cannot post anything better right now.
  8. #8
    A full test case is appreciated.

Similar Threads

  1. [CLOSED] Disable items of combobox and reenable them based on condition
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 18
    Last Post: Sep 05, 2013, 10:21 AM
  2. [CLOSED] Create window for input query condition ?
    By Zenalyse in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 05, 2013, 4:14 AM
  3. Replies: 0
    Last Post: May 01, 2012, 9:43 AM
  4. How to stop deleting the records based on the condition.
    By kondareddy1984 in forum 1.x Help
    Replies: 1
    Last Post: Nov 15, 2011, 5:53 AM
  5. Replies: 1
    Last Post: Apr 01, 2009, 12:24 PM

Tags for this Thread

Posting Permissions