gpt4 book ai didi

c# - 带有 PartialView 的 ASP.NET MVC 2 View - PartialView 打开新页面

转载 作者:太空宇宙 更新时间:2023-11-03 16:46:08 25 4
gpt4 key购买 nike

我的代码在 VS2010 C# 中完美运行,但一旦发布到 IIS7,PartialView(记录列表)不会在 View 中呈现...它滚动到一个没有数据的新页面,除了从 SQL 检索的正确记录计数服务器。 SQL 服务器在单独的盒子上。

我已经在此站点上搜索了几个小时,但没有找到解决方案。

使用 RenderPartial 查看:

   <table style="width:100%">
<tr>
<td>
<h3>Outage Tracking List (Open or Active)</h3>
</td>
<td style="text-align:right">
<h1><%: ViewData["ApplicationName"]%></h1>
</td>
</tr>
</table>

<% Html.RenderPartial("OutageSearch",this.ViewData.Model); %>

局部 View :

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<OutageTrackingWebSite.Models.OutageViewModel" %>
<div>

<script language="javascript" type="text/javascript">

function OutageSearch() {

$("#OutageSearchForm #CurrentPageNumber").val("1");
PostSearchForm();

}

各种功能然后是局部 View 的其余部分

  <% using (Ajax.BeginForm("OutageSearch", null,
new AjaxOptions { UpdateTargetId = "DivOutageSearchResults", OnComplete="OutageSearchComplete" },
new { id = "OutageSearchForm" })) { %>

<table style="background-color: #ebeff2; width: 100%; border:solid 1px #9fb8e9" cellspacing="2" cellpadding="2">
<tr>
<td style="width: 60%; text-align: left">
<input id="btnSearch" onclick="OutageSearch();" type="submit" value="List Open/Active" />
</td>
</tr>
</table>

<div id="DivOutageSearchResults">
<% Html.RenderPartial("OutageSearchResults", this.ViewData.Model); %>
</div>

<% } %>

额外的 PartialView

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<%OutageTrackingWebSite.Models.OutageViewModel" >

    <input name="CurrentPageNumber" type="hidden" id="CurrentPageNumber" value="<%=Model.CurrentPageNumber%>" />
<input name="TotalPages" type="hidden" id="TotalPages" value="<%=Model.TotalPages%>" />
<input name="SortBy" type="hidden" id="SortBy" value="<%=Model.SortBy%>" />
<input name="SortAscendingDescending" type="hidden" id="SortAscendingDescending" value="<%=Model.SortAscendingDescending%>" />

<input name="PageSize" type="hidden" id="PageSize" value="9" />

<script language="javascript" type="text/javascript">
function GetOutageDetails(OutageID) {

if (formIsDisabled == false) {

DisableForm();

formData = "OutageID=" + OutageID;

setTimeout(PostOutageIDToServer, 1000);

}

}

function PostOutageIDToServer() {

$.post("/Outage/GetOutageInformation", formData, function (data, textStatus) {
OutageUpdateComplete(data);
}, "json");

}

Controller


public ActionResult DisplayOutageList()
{


Models.OutageViewModel outageViewModel = new Models.OutageViewModel();

outageViewModel.TotalPages = 0;
outageViewModel.TotalRows = 0;
outageViewModel.CurrentPageNumber = 0;

ViewData.Model = outageViewModel;

string applicationName = Convert.ToString( System.Configuration.ConfigurationManager.AppSettings["ApplicationName"]);

ViewData["ApplicationName"] = applicationName;

return View("OutageMaintenance");
}

///
/// Outage Search
///
///
public PartialViewResult OutageSearch()
{
long totalRows;
long totalPages;
bool returnStatus;
string returnErrorMessage;

OutageBLL OutageBLL = new OutageBLL();

Models.OutageViewModel outageViewModel = new Models.OutageViewModel();

this.UpdateModel(outageViewModel);

List Outages = OutageBLL.OutageSearch(
outageViewModel,
outageViewModel.CurrentPageNumber,
outageViewModel.PageSize,
outageViewModel.SortBy,
outageViewModel.SortAscendingDescending,
out totalRows,
out totalPages,
out returnStatus,
out returnErrorMessage);

ViewData["Outages"] = Outages;

outageViewModel.TotalPages = totalPages;
outageViewModel.TotalRows = totalRows;

ViewData.Model = outageViewModel;

return PartialView("OutageSearchResults");

}


///
/// Get Outage Information
///
///
public JsonResult GetOutageInformation()
{

bool returnStatus;
string returnErrorMessage;
List returnMessage;

OutageBLL outageBLL = new OutageBLL();

Models.OutageViewModel outageViewModel = new Models.OutageViewModel();

this.TryUpdateModel(outageViewModel);

Outage outage = outageBLL.GetOutageInformation(
outageViewModel.OutageID,
out returnStatus,
out returnErrorMessage,
out returnMessage);

outageViewModel.UpdateViewModel(outage, typeof(Outage).GetProperties());

outageViewModel.ReturnMessage = returnMessage;
outageViewModel.ReturnStatus = returnStatus;
outageViewModel.OutageScheduledDate = UtilitiesBLL.FormatDate(outageViewModel.ScheduledDate);
outageViewModel.OutagePlannedDuration = UtilitiesBLL.FormatDuration(outageViewModel.PlannedDuration);

return Json(outageViewModel);

}

最佳答案

检查部署版本中包含的 JavaScript 文件。如果您缺少某些文件(MicrosoftMvcAjax.js、jQuery.js),页面可能只是发布而不是使用 Ajax 发布。

关于c# - 带有 PartialView 的 ASP.NET MVC 2 View - PartialView 打开新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5928860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com