2015-02-07 61 views
4

在我的項目中,我需要在Kendo窗口中放置一些窗體。這些形式是在另一個局部視圖。我用這個加載的局部視圖:在劍道窗口中使用窗體的部分視圖

@(Html.Kendo().Window() 
     .Name("editPasswordPopUp") 
     .Visible(false) 
    .Modal(true) 
    .Width(600) 
    .Height(500) 
    .Position(settings => 
      settings.Top(70).Left(200)) 
     .Title("Edit your password") 
     .Content("loading user info...") 
    .LoadContentFrom("EditPassword", "Member") 
     .Iframe(true) 
     .Resizable() 
     .Draggable() 
    ) 

的PartialView的動作:

public ActionResult EditPassword() 
{ 
    return PartialView(); 
} 

[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult EditPassword(EditPasswordViewModel viewModel) 
{ 
    [...] 
    return RedirectToAction("Profile", "Member", new {id = viewModel.Id}); 
    [...] 
} 

這裏是我PartialView:

@model Devoteam.CustomerPortal.ViewModels.EditPasswordViewModel 
@{ 
ViewBag.Title = "Edit"; 
Layout = null; 
} 

@Styles.Render("~/Content/css") 
@Scripts.Render("~/bundles/jquery") 
@Scripts.Render("~/bundles/jqueryval") 
@Scripts.Render("~/bundles/kendo") 

@using (Html.BeginForm()) 
{ 
    @Html.AntiForgeryToken() 
    @Html.Partial("_GenericMessage") 

    <div id="messageError"> 
    @Html.ValidationSummary() 
    </div> 
    // FIELDS 
    <div class="buttons"> 
    <input type="submit" value="Confirm" class="big-button" /> 
    <input type="submit" value="Cancel" class="big-button" /> 
    </div> 
} 

當我點擊按鈕,打開Kendo窗口,正確加載部分視圖。 當我提交表單時,正確調用了該操作。 這是我的問題:當控制器完成它的工作時,我調用RedirectToAction來重定向用戶。但是頁面加載在Kendo窗口而不是主窗口中。有沒有解決方案來關閉Kendo窗口?

第二個問題:如何在按下取消按鈕時關閉Kendo窗口?

預先感謝您。 (對不起,我的英語不好,這不是我的母語)

+2

你設法得到這個重定向排序?關閉窗口你可以做onclick =「parent.jQuery('#windowName')。data('kendoWindow')。close();」 – Dante 2015-02-24 14:02:10

回答

1

而不是在PartialView的服務器端控制器代碼提交後自動關閉窗口/重定向,您可以將它作爲提交例程中的一部分JavaScript的。

  1. 而不是你的PartialView中的return RedirectToAction("Profile", "Member", new { id: viewModel.Id },只是做return null
  2. 如果您需要在窗口關閉後刷新父窗口,並且這是我在您的問題中沒有看到足夠的代碼來從您的主窗體首先啓動窗口的原因,但是您會綁定事件有沒有你的KendoWindow「閉」:

    <input type="button" value="Edit Password" onclick="editPassword()" /> 
    
    <script type="text/Javascript"> 
        function editPassword() { 
         var url = '@Url.Action("EditPassword", "Password")?viewModel=' + '@Model'; 
         var win = ('#editPasswordPopUp').data('kendoWindow').bind("close", function(e) { 
          // Whatever you put here will run after your PartialView 
          window.top.location.reload(); // reloads parent onclose of Kendo window 
         }); 
         win.refresh(url); 
         win.open(); 
         win.center(); 
        } 
    </script> 
    
  3. 如果然後希望窗口自動關閉並刷新提交後的父母,你需要一個自定義函數做submit(),而不是使用,你有input type="submit" 。這樣,您就能夠像但丁建議,添加窗口關閉事件到您的PartialView:

    <input type="button" value="Confirm" class="big-button" onclick="formSubmit() /> 
    
    <script type="text/Javascript"> 
        function formSubmit() { 
         $('form').submit(); 
         parent.$('#editPasswordPopUp').data('kendoWindow').close(); 
        } 
    </script> 
    
  4. Cancel按鈕關閉窗體,你會做同樣的事情。使其成爲type="button"而不是type="submit",將其放入onclick以轉到使用同一行關閉窗口的功能:parent.$('#editPasswordPopUp').data('kendoWindow').close();