How to open Kendo window after POST

Setting
In MVC application I have 2 views. The main view that links to the Layout view Has a Show button. Then I have another generic view that has a kendo upload control. The load view does NOT reference the _Layout view, but in a shared folder, so I can reuse it.

Requirement When the user clicks the "Show" button in the main window, I want to show the "Load" window in a pop-up window. In the popup, if the user does not select a file, I want to show the error message in the same popup.

Questions
When the user clicks the upload button without selecting a file, the model is submitted to the server for the Upload method as expected. Inside the if method

ModelState.IsValid == false

im going back to the same view. But then I get the error

0x800a1391 - JavaScript runtime error: "jQuery" is undefined.

now i can keep pushing continue in the IE error window and i finally get the download view and i could see the error in the ValidationSummary however it didn't show up as a popup but instead show as a simple html page

Below is my code

Main view

@model MainModel

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script>
    $(document).ready(function () {
        var uploadwindow = $("#uploadwindow");

        $("#btnShow").click(function (e) {
            uploadwindow.data("kendoWindow")
                .open()
                .center();
        });

    });
</script>

<button type="button" class="btn btn-default" id="btnShow">Show</button>

@(Html.Kendo().Window()
.Name("uploadwindow")
.Title("Select the files to upload")
.Width(600)
.Modal(true)
.Visible(false)
.LoadContentFrom("Upload", "Main")
)
      

Run codeHide result


Download performance

@model UploadModel
@using (Html.BeginForm("Upload", "Main", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary()
    @(Html.Kendo().Upload().Name("files"))
    <button type="submit">Upload</button>
}
      

Run codeHide result


public class MainController : Controller
    {
        public ActionResult Index()
        {
            MainModel model = new MainModel()
            return View(model);
        }

        public ActionResult Upload()
        {
            UploadModel model = new UploadModel();
            return View(model);
        }

        [HttpPost]
        public ActionResult Upload (UploadModel model)
        {
            if (ModelState.IsValid == false)
            {
               //I want stay on the same Upload view to show error messages
		 //Here I get JQuery exception when model is not valid
                return View(model); 
            }
            else
            {
		       // Do something here and Close the POPUP Window
            }
        }
    }
      

Run codeHide result


    public class UploadModel
    {
        [Required(ErrorMessage = "Please click the browse button and select a file.")]    
        public IEnumerable<HttpPostedFileBase> Files { get; set; }     
    }
      

Run codeHide result


+3


source to share





All Articles