以下代码在托管后无法在服务器上运行,但在localhost上运行正常。代码是否有任何问题。
控制器:
[HttpGet]
public ActionResult SelectCustomerByID(Receipt model, string secondValue)
{
int CustID = 0;
if (secondValue != null && secondValue != "")
CustID = Convert.ToInt32(secondValue);
ObservableCollection<Receipt> ReceiptList = new ObservableCollection<Receipt>();
Receipt Receipt = new Models.Receipt();
if (CustID != 0)
ReceiptList = Receipt.GetReceiptListByCustID(CustID);
else
ReceiptList = Receipt.GetReceiptList();
ViewData["Count"] = ReceiptList.Count;
return PartialView("_Recepitgrid", ReceiptList);
}
部分视图中的脚本:
<script type="text/javascript">
$(document).ready(function () {
var str = ('@ViewData["Count"]');
if (str == '0')
ShowProduct();
else
ShowGrid();
});
function ShowProduct() {
document.getElementById("gridContent").style.display = 'none';
document.getElementById("ShowNodata").style.display = 'block';
return false;
}
function ShowGrid() {
document.getElementById("gridContent").style.display = 'block';
document.getElementById("ShowNodata").style.display = 'none';
return false;
}
</script>
PartialView:
<div id="divgrid" >
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="gridContent" class="rounded-corners">
@grid.GetHtml(
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
columns: grid.Columns(
grid.Column(header: "S.No", format: item => Item.WebGrid.Rows.IndexOf(item) + 1),
grid.Column("Recepit_No", "Recepit Number", style: "PName"),
grid.Column(null, null, format: @<input type="hidden" name="Id" id="ID" value="@item.ID"/>),
grid.Column("Cust_Name", "Cust Name", style: "PName"),
grid.Column("Pay_Amount", "Paid Amount", style: "Curency"),
grid.Column("Pay_Mode", "Paid Mode", style: "IName"),
grid.Column("Bank_Name", "Bank Name", style: "Weight"),
grid.Column("Bank_Address", " Bank Address", style: "MakingCharge"),
grid.Column("ChequeNo", "ChequeNo", style: "Certification"),
grid.Column("Cheque_Date", " Cheque Date", style: "Price"),
grid.Column("Date", "Date", format: item => ((item.Date == null) ? "" : item.Date.ToString("dd/MM/yyyy")), style: "Price"),
grid.Column("Edit", "", @<a href='../Admin/EditReceipt?Id=@item.Id' ><img src="~/Images/edit.png" alt='Edit' /></a>, style: "width:10%"),
grid.Column(header: "Delete", format: @<text><a href="@Url.Action("DeleteReceipt", "Admin", new { Id = item.ID })" onclick="javascript:return confirm('Are you sure you'd like to delete this product?');"><img src="../Images/delete.png" alt='Delete' /></a></text>)
))
</div>
</div>
答案 0 :(得分:1)
(提供一系列选项作为答案,而不是变成一个巨大的评论垃圾邮件主题。)
听起来你的应用程序和逻辑很好,但是当你转向生产时,你可能会在不同的数据源上运行。
您在局部视图中对var str = ('@ViewData["Count"]');
进行了引用。添加调试或警报以显示该值实际是什么。如果您发布的网站显示ViewData [“Count”] = 0,那么您的部分视图就是遵循您要告诉它的内容。
如果ViewData["Count"]
中有有效号码,接下来要做的就是确认MODEL
中的数据。尝试在网格之前的部分视图中包含一些临时调试语句,如下所示:
<span id="debugCheck1">is the model null? = @(Model==null) </span>
<span id="debugCheck2">Model has this many rows? = @Model.Count </span>
<div id="divgrid" >
@{
..
最后,获取Firefox并安装firebug(或您选择的浏览器的任何webdeveloper工具)并使用NET面板检查显示404错误的任何请求。使用它来查看ajax请求并查看发送的实际结果。
祝你好运。