This is a followup to my question here: Why are my "replacement parameters" getting transformed into empty strings?
Okay, maybe somebody can help me understand what's going on here (note that I didn't write this code, so I'm approaching it from the perspective of a problem bear that has just been heli-dropped into unfamiliar terrain).
As it seemed more natural/conventional to do so, I changed my handler from a submit button click handler to the form's submit handler:
$("form").submit(function () {
The model values that are causing the whole process to fail being they are being resolved to empty strings (GUID, SerialNumber, and ReportName) are declared in the corresponding model's base class:
public class ReportModelCore
{
public string GUID { get; set; }
public string SerialNumber { get; set; }
public string ReportName { get; set; }
public bool DataSourceSuccess { get; set; }
public string DataSourceMessage { get; set; }
public string message { get; set; }
}
...and these core members are conditionally assigned values in the Controller:
model.SerialNumber = Serial.ToString();
model.ReportName = "ReceiptCollection";
DatasourceCreatorResultContract result = Operations.CreateDataSource(criteria);
if (result.type == ResultType.Success)
{
model.GUID = result.GUID;
. . .
}
else if (result.type == ResultType.SuccessWithAlert)
{
model.GUID = result.GUID;
. . .
}
else // Failure < no GUID assigned in diesem Fall
{
. . .
...but I don't grok how they are expected to have values in the form's submit handler, where they are referenced:
. . .
if (resultsText == "0") {
$("#NumberOfResults").css("color", "red");
} else {
var href = '/@ConfigurationManager.AppSettings["ThisApp"]/TLDCriteria/LoadReport';
// report_parms (sic) is referenced from LoadReport
var report_parms = {
GUID: "@Model.GUID",
SerialNumber: "@Model.SerialNumber",
ReportName: "@Model.ReportName"
};
window.open(href, "report_window", "resizable=1, width=850, left=" + (screen.width / 2 - 425));
}
. . .
IOW: When does the Controller's [HttpPost] ActionResult get fired? Before the form submit event finishes? If so, when exactly?
If not, why is this code referencing those model members which could not have been assigned values yet (and when they are empty strings, as they currently are, it causes the whole kit and kaboodle to ceremoniously but ignominiously fail)?
UPDATE
report_parms are, as the comment notes, referenced from LoadReport, which is a Silverlight-infested file with:
<script type="text/javascript">
function get_user_name() {
return "@User.Identity.Name";
}
function get_xml_data() {
return window.opener.xml_data;
}
function get_receipt_parms() {
return window.opener.receipt_parms;
}
function get_report_parms() {
return window.opener.report_parms;
}
</script>
Stepping through it in Firefox > Script, it indeed shows the values of those three members of "report_parms" being empty strings; I'm not surprised, but again: is there a reason why somebody would expect those vals to be populated at this point - and do they need to be? If so, how?
UPDATE 2
MisterJames,
Yes, there is a:
return View(model);
...at the end of the [HttpPost] ActionResult, but it turns out it is never reached; apparently another problem is preventing that from occurring; acutally, it seems like kind of a "chicken-and-egg" problem: I was thinking that the reason this code:
DatasourceCreatorResultContract result = Operations.CreateDataSource(criteria);
...was failing was because the criteria object passed to CreateDataSource() was not quite right, and that was because those report_parms were empty; But it might be, OTOH, that the problem lies elsewhere. To wit: the "if (result.type == ResultType.Success)" line is never reached, because the code fails due to lack of proper authentication, apparently.
I thought this was caused by my report_parms problem, but perhaps my report_parms problem is caused by this!
The entire section of code is:
. . .
model.SerialNumber = Serial.ToString();
model.ReportName = "ReceiptCollection";
DatasourceCreatorResultContract result = Operations.CreateDataSource(criteria);
if (result.type == ResultType.Success) // <-- this is not reached; "conn.Open();" in another class fails before it can be
{
model.GUID = result.GUID;
model.DataSourceSuccess = true;
model.NumberOfResults = result.Count;
model.message = String.Format("{0} results", result.Count);
}
else if (result.type == ResultType.SuccessWithAlert)
{
model.GUID = result.GUID;
model.DataSourceSuccess = true;
model.NumberOfResults = result.Count;
model.message = result.Message;
}
else // Failure
{
model.DataSourceMessage = result.Message;
model.DataSourceSuccess = false;
model.NumberOfResults = 0;
model.message = result.Message;
}
}
return View(model);