【发布时间】:2012-11-09 00:25:53
【问题描述】:
我有一个布尔模型变量,它的值应该设置为 TRUE,以便在返回控制器时执行一个过程。
它在我的本地机器上绝对没问题工作,但在远程网络服务器上却不行。
有人可以告诉我我缺少什么吗?以下是“布丁证明”: 问题中的布尔值是“ShouldGeneratePdf”;
型号:
namespace PDFConverterModel.ViewModels
{
public partial class ViewModelTemplate_Guarantors
{
public ViewModelTemplate_Guarantors()
{
Templates = new List<PDFTemplate>();
Guarantors = new List<tGuarantor>();
}
public int SelectedTemplateId { get; set; }
public List<PDFTemplate> Templates { get; set; }
public int SelectedGuarantorId { get; set; }
public List<tGuarantor> Guarantors { get; set; }
public string LoanId { get; set; }
public string DepartmentId { get; set; }
public bool isRepeat { get; set; }
public string ddlDept { get; set; }
public string SelectedDeptText { get; set; }
public string LoanTypeId { get; set; }
public string LoanType { get; set; }
public string Error { get; set; }
public string ErrorT { get; set; }
public string ErrorG { get; set; }
public bool ShowGeneratePDFBtn { get; set; }
public bool ShouldGeneratePdf { get; set; }
}
}
母版页:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.2.913/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.2.913/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2012.2.913/kendo.blueopal.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/kendo/2012.2.913/kendo.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo/2012.2.913/kendo.aspnetmvc.min.js")"></script>
</head>
<body>
<div class="page">
<header>
<div id="title">
<h1>BHG :: PDF Service Generator</h1>
</div>
</header>
<section id="main">
@RenderBody()
</section>
<footer>
</footer>
</div>
</body>
</html>
查看:
@model PDFConverterModel.ViewModels.ViewModelTemplate_Guarantors
@using (Html.BeginForm("ProcessForm", "Home", new AjaxOptions { HttpMethod = "POST" }))
{
<table style="width: 1000px">
@Html.HiddenFor(x => x.ShouldGeneratePdf)
<tr>
<td>
<img alt="BHG Logo" src="~/Images/logo.gif" />
</td>
</tr>
<tr>
<td>
@(Html.Kendo().IntegerTextBox()
.Placeholder("Enter Loan Id")
.Name("LoanId")
.Format("{0:#######}")
.Value(Convert.ToInt32(Model.LoanId))
)
</td>
</tr>
<tr>
<td>@Html.Label("Loan Type: ")
@Html.DisplayFor(model => Model.LoanType)
</td>
<td>
<label for="ddlDept">Department:</label>
@(Html.Kendo().DropDownListFor(model => Model.ddlDept)
.Name("ddlDept")
.DataTextField("DepartmentName")
.DataValueField("DepartmentID")
.Events(e => e.Change("Refresh"))
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetDepartments", "Home");
});
})
.Value(Model.ddlDept.ToString())
)
</td>
</tr>
@if (Model.ShowGeneratePDFBtn == true)
{
if (Model.ErrorT == string.Empty)
{
<tr>
<td>
<u><b>@Html.Label("Templates:")</b></u>
</td>
</tr>
<tr>
@for (int i = 0; i < Model.Templates.Count; i++)
{
<td>
@Html.CheckBoxFor(model => Model.Templates[i].IsChecked)
@Html.DisplayFor(model => Model.Templates[i].TemplateId)
</td>
}
</tr>
}
else
{
<tr>
<td>
<b>@Html.DisplayFor(model => Model.ErrorT)</b>
</td>
</tr>
}
if (Model.ErrorG == string.Empty)
{
<tr>
<td>
<u><b>@Html.Label("Guarantors:")</b></u>
</td>
</tr>
<tr>
@for (int i = 0; i < Model.Guarantors.Count; i++)
{
<td>
@Html.CheckBoxFor(model => Model.Guarantors[i].isChecked)
@Html.DisplayFor(model => Model.Guarantors[i].GuarantorFirstName) @Html.DisplayFor(model => Model.Guarantors[i].GuarantorLastName)
</td>
}
</tr>
}
else
{
<tr>
<td>
<b>@Html.DisplayFor(model => Model.ErrorG)</b>
</td>
</tr>
}
}
<tr>
<td>
<input type="submit" name="submitbutton" id="btnRefresh" value='Refresh' />
</td>
@if (Model.ShowGeneratePDFBtn == true)
{
<td>
<input type="submit" name="submitbutton" id="btnGeneratePDF" value='Generate PDF' />
</td>
}
</tr>
<tr>
<td style="color: red; font: bold">
@Model.Error
</td>
</tr>
</table>
}
<script type="text/javascript">
$('#btnRefresh').click(function () {
Refresh();
});
function Refresh() {
var LoanID = $("#LoanID").val();
if (parseInt(LoanID) != 0) {
$('#ShouldGeneratePdf').val(false)
document.forms[0].submit();
}
else {
alert("Please enter a LoanId");
}
}
//$(function () {
// //DOM loaded
// $('#btnGeneratePDF').click(function () {
// DisableGeneratePDF();
// $('#ShouldGeneratePdf').val(true)
// });
//});
//function DisableGeneratePDF() {
// $('#btnGeneratePDF').attr("disabled", true);
// $('#btnRefresh').attr("disabled", true);
//}
$('#btnGeneratePDF').click(function () {
alert("inside click function");
DisableGeneratePDF();
$('#ShouldGeneratePdf').val(true)
tof = $('#ShouldGeneratePdf').val();
alert("ShouldGeneratePdf set to " + tof);
});
function DisableGeneratePDF() {
alert("begin DisableGeneratePDF function");
$('#btnGeneratePDF').attr("disabled", true);
$('#btnRefresh').attr("disabled", true);
alert("end DisableGeneratePDF function");
}
</script>
控制器:
[HttpPost]
public ActionResult ProcessForm(string submitbutton, ViewModelTemplate_Guarantors model, FormCollection collection)
if ((submitbutton == "Refresh") || (submitbutton == null) && (model.ShouldGeneratePdf == false))
{
}
else if ((submitbutton == "Generate PDF") || (model.ShouldGeneratePdf == true))
{
}
上面脚本中的“警报”与远程服务器上的“警报”完全相同。最后一个警报显示 bool 变量的值为“true”。但是,当我对隐藏变量进行页面源视图时,结果如下。
页面加载时和最后一个警报按钮完成时隐藏变量的值如下:
我的本地机器:
远程机器:
如你所见,当进程执行时,我机器上的值设置为 true。但是,在远程机器上,它被设置为 false,然后它不会执行。
为什么模型中的值没有在远程机器上返回为 TRUE?
【问题讨论】:
标签: jquery asp.net asp.net-mvc-4