Model value not being set on return from View to Controller
- by sagesky36
I have a boolean model variable who's value is supposed to be set to TRUE in order to perform a process on return back into the Controller.
It works absolutely fine on my local machine, but not on the remote web server.
Can somebody PLEASE inform me what I am missing? Below is the "proof of the pudding": The boolean value in quesion is "ShouldGeneratePdf";
MODEL:
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; }
}
}
MasterPage:
<!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>
View:
@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>
Controller:
[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))
{
}
The "Alerts" in the script above come out to exactly what they should be on the remote server. The last alert shows that the value of the bool variable is "true". However, when I do page source views of the hidden variable, below is the result.
The values of the hidden variable when the page loads and when the last alert button finishes are as follows:
My local machine:
The remote machine:
As you can see, the value on my machine is set to true when the process executes. However, on the remote machine, it is set to false where it then doesn't excute.
Why isn't the value in the model being returned as TRUE on the remote machine?