问题
This is the code when "at rest":
var report_parms = {
GUID: "@Model.GUID",
SerialNumber: "@Model.SerialNumber",
ReportName: "@Model.ReportName"
};
This is what it looks like at run-time, when stepping through the jQuery:
var report_parms = {
GUID: "",
SerialNumber: "",
ReportName: ""
};
...and this is the exception I get because those strings are empty:
System.NullReferenceException was unhandled by user code Message=Object reference not set to an instance of an object. StackTrace: at TLDReporter_SL.App.Application_Startup(Object sender, StartupEventArgs e) at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
...in this C# method:
private void Application_Startup(object sender, StartupEventArgs e)
{
ScriptObject Parms = (ScriptObject)HtmlPage.Window.Invoke("get_report_parms");
string ReportName = Parms.GetProperty("ReportName").ToString(); <--- This is the line that blows up
switch (ReportName)
{
default:
this.RootVisual = new ReceiptRpt();
break;
}
}
So my question is (this is legacy code I'm trying to grok): What is that "@Model.Bla" stuff supposed to do? Is anybody familiar with this sort of "magic"? It seems odd to me that:
0) The word "model" is capitalized ("Model"), whereas the model referenced in Razor syntax above is not:
@model TLDReporter.Models.TLDSalesReceiptCriteriaModel
And!:
1) Those "replacement parameters" are encased in quotes.
Is this something totally "home[grown,spun]" that I'll have to unravel myself, or is this sort of thing something of a known quantity?
回答1:
What is that "@Model.Bla" stuff supposed to do?
That Razor syntax means simply, render the property "Bla" of the page model. This line:
@model TLDReporter.Models.TLDSalesReceiptCriteriaModel
indicates the type of the page model. You'll have to find the controller code to figure out exactly how the instance of that class is being returned (or not). You should be able to find a class like "XyzController" with a method returning "ActionResult" or similar, that has something like this:
var model = new TLDReporter.Models.TLDSalesReceiptCriteriaModel();
return View(model);
来源:https://stackoverflow.com/questions/18346600/why-are-my-replacement-parameters-getting-transformed-into-empty-strings