ASP.NET MVC 2 视图与 PartialView - PartialView 打开新页面

发布于 2024-11-05 14:43:36 字数 6030 浏览 6 评论 0原文

我的代码在 VS2010 C# 中运行良好,但一旦发布到 IIS7,PartialView(记录列表)不会在视图中呈现...它会滚动到一个没有数据的新页面,除了从 SQL Server 检索到的正确记录计数之外。 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); %>

PartialView:

<%@ 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();

    }

各种功能,然后是partialview的其余部分

  <% 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");

         }
         

控制器


       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);

        }

My code works perfectly in VS2010 C# but once published to IIS7 the PartialView (list of records) does not get rendered in the View...it rolls to a new page without the data except for the correct record count retrieved from SQL server. SQL server is on separate box.

I have searched for hours on this site with no luck finding a resolution.

View with the 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); %>

PartialView:

<%@ 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();

    }

Various functions then the rest of the partialview

  <% 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>

<% } %>

additional 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);

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2024-11-12 14:43:36

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

Check your included JavaScript files on the deployed version. If you are missing some files (MicrosoftMvcAjax.js, jQuery.js), the page could simply be posting instead of using an Ajax post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文