Close KendoUI Window & reload Parent page on successful login

I have a View which contains "button" & KendoUI window which is not visible by default.

Index.cshtml:

@(Html.Kendo().Button()
    .Name("btnLogin")
    .Content("Login")
    .Events(e => e.Click("LoginBtn")))

@{Html.Kendo().Window()
.Name("windowLogin")
.Title("Login")
.Content("loading user info...")
.LoadContentFrom("Login", "Account")
.Modal(true)
.Visible(false)
.Iframe(true)
.Draggable()
.Resizable()
.Render();
}

On click of button, modal window is opened which contains form. "Login" action is reurning View containing complete form.

Login.cshtml:

<h2>Login Details</h2>    
@Html.ValidationMessage("error")
@using (Html.BeginForm("Login", "Account", FormMethod.Post))
{
<table>
    <tr>
        <td>
            @Html.Label("UserName: ")      
        </td>     
        </td>
        <td>
            @Html.TextBoxFor(user => user.UserName)
        </td>
        <td>
            @Html.ValidationMessageFor(user => user.UserName, "Enter Name")
        </td>
    </tr>

    <tr></tr>

    <tr>
        <td>
            @Html.Label("Password: ")
        </td>
        <td>
            @Html.PasswordFor(user => user.Password)
        </td>
        <td>
            @Html.ValidationMessageFor(user => user.Password, "Enter Password")
        </td>
    </tr>

    <tr></tr>

    <tr>
        <td>
            <input type="submit" value="Login" />
        </td>
        <td>
            <input id="CancelButton" type="button" value="Cancel"  />
        </td>            
    </tr>
</table>
}

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

AccountController.cs:

[HttpPost]
    public ActionResult Login(User user)
    {
        var userDetails = ExecuteQueries.GetUser(user);

        if (userDetails != null)
        {
            Session["userName"] = userDetails.UserName;                
            //FormsAuthentication.RedirectFromLoginPage(user.UserName, true);          
        }

        else
        {
            ModelState.AddModelError("error", "UserName or Password is incorrect");
        }

        return View("Login");
    }

The problem I am facing is that I am not able to close modal window & reload the parent screen. After successful login my new window is opening in the same modal window, what I want is close the modal window & refresh parent screen.

Answers


It's as simple as calling a window.Close(). This script is inside my " Kendo Windowed" view. On successful login before you return the view just set a propoerty on your model to true or something. Model.CloseWindow = true; and put this code in your View Engine

@if (Model.CloseWindow == true)
{
<script>     
 // close the popup
var w = window.parent.$("#createManualProposalWindow").data("kendoWindow");
w.close();

</script>
}

Here's how the window is defined.

@(Html.Kendo().Window()
.Name("createManualProposalWindow")
.Title("Manual Proposal Details")
.Draggable(true)
.Resizable()
.Scrollable(false)
.Width(880)
.Height(650)
.Visible(false)
.Iframe(true)
.Modal(true)
.Events(e => e            
    .Close("ManualWindow_close"))  
 )

You'll see the close event, inside that event you can handle refreshing of the parent page.

function ManualWindow_close() {         
     var aggGrid = $("#agg_grid").data("kendoGrid");  
     aggGrid.dataSource.read();

     var grid = $("#grid").data("kendoGrid");
     grid.dataSource.page(1);

     refreshGetContractTotals();

 }

Need Your Help

Android access django rest framework makes HTTP 500

android django apache http django-rest-framework

I'm an experienced developer with android and currently i am developing android application that has Django as its server side on heroku cloud.

Android - VerifyError

android verifyerror

this is an error I am getting in Android Developer Console from hundreds of my users.