[英]url.action, jquery, and mvc
我正在構建一個應用程序,它將關閉服務器,對服務器執行ping操作,並在服務器已關閉時通知用戶。 如果未成功關閉,則允許用戶“重試”。 我可以讓應用程序第一次正確處理邏輯,但是當我實現“重試”功能時,它不會重新處理“關機”操作。 我認為它必須與緩存有關,但我對緩存了解不足,無法知道從哪里開始尋找緩存。 有任何想法嗎?
這是我的代碼:
調節器
//URL: Build/Progress
public ActionResult Progress()
{
return View();
}
////URL: Build/MoveDevice
public ActionResult ShutdownStatus()
{
ImageInfo ImageInfo = new ImageInfo();
FarmInfo FarmInfo = new FarmInfo();
ProgressModel ProgressModel = new ProgressModel();
if ((Session["ShutdownStatus"] as string) == "Success")
{
ProgressModel.ShutdownStatus = 1;
return View(ProgressModel);
}
else
{
ImageInfo = svcImage.GetImageInfoByImageId(Session["ImageName"].ToString());
string Farm = ImageInfo.FarmId.ToString();
FarmInfo = svcFarm.GetFarmByFarmId(Farm);
svcImageSvc.ShutdownDevice(Session["Username"].ToString(), Session["Password"].ToString(), Session["Domain"].ToString(),
FarmInfo.farmName, ImageInfo.Device, ImageInfo.ImageHistory.Status, ImageInfo.PVSHost, ImageInfo.PVSAccount);
ProgressModel.ShutdownStatus = svcImageSvc.PingDevice(ImageInfo.Device);
return View(ProgressModel);
}
}
視圖(Progress.aspx)
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Progress
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1>Progress</h1>
<hr />
<!-- Shutdown Status -->
<div class="panel" id="panel1"><img src="../../Assets/Images/load.gif" /></div>
<script type="text/javascript">
$.get('<%= Url.Action("ShutdownStatus", "Build", null) %>',
function (data) {
$('#panel1').replaceWith(data);
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="FooterContent" runat="server">
</asp:Content>
查看(ShutdownStatus.asxc)
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PvsUtil.App.Core.Models.ProgressModel>" %>
<% using (Html.BeginForm())
{ %>
<% if (Model.ShutdownStatus == 1)
{ %>
<%: Session["ShutdownStatus"] = "Success" %>
<p>
Server shutdown succesfully
</p>
<% } %>
<% if (Model.ShutdownStatus == 2)
{ %>
<p>Server did not shutdown within 1 minute. Please check the server and try again.</p>
<%: Html.ActionLink("Try Again", "Progress", "Build") %>
<% } %>
<% if (Model.ShutdownStatus == 3)
{ %>
<p>An error has occurred. Please check the server and try again.</p>
<%: Html.ActionLink("Try Again", "Progress", "Build") %>
<% } %>
<% } %>
我相信緩存實際上是由jQuery完成的。 將$ .get更改為$ .post,看看是否可行。 如果是這樣,您仍然可以使用$ .get,但是您需要設置以下選項:
cache: false
HTH,布萊恩
嘗試添加:
[OutputCache( Location = OutputCacheLocation.None )]
到您的控制器(或您不想緩存的每個動作)。
您要做的另一件事是將您的JavaScript包裝在document.ready()處理程序中。 這並不是嚴格必要的,因為腳本會在它引用的元素之后出現,但這仍然是一個好習慣-您也可以將其移到主體標記的上方,但這更多的是優化。
<script type="text/javascript">
$(function() { // execute on document ready
$.get('<%= Url.Action("ShutdownStatus", "Build", null) %>',
function (data) {
$('#panel1').replaceWith(data);
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.