为什么我的“替换参数"变成空字符串? [英] Why are my "replacement parameters" getting transformed into empty strings?

查看:147
本文介绍了为什么我的“替换参数"变成空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是静止"时的代码:

var report_parms = {
    GUID: "@Model.GUID",
    SerialNumber: "@Model.SerialNumber",
    ReportName: "@Model.ReportName"
};

这是运行时通过jQuery时的样子:

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 Message =对象引用未设置为对象的实例. 堆栈跟踪: 在TLDReporter_SL.App.Application_Startup(对象发送者,StartupEventArgs e) 在MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex,Delegate handlerDelegate,Object sender,Object args) 在MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj,IntPtr unmanagedObjArgs,Int32 argsTypeIndex,Int32 actualArgsTypeIndex,String eventName,UInt32标志)处

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)

...在此C#方法中:

...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;
        }
    }

所以我的问题是(这是我要尝试的遗留代码):"@ Model.Bla"应该做什么?有没有人熟悉这种魔术"?我觉得这很奇怪:

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)模型"一词大写(模型"),而以上Razor语法中引用的模型不是:

0) The word "model" is capitalized ("Model"), whereas the model referenced in Razor syntax above is not:

@model TLDReporter.Models.TLDSalesReceiptCriteriaModel

然后!:

1)那些替换参数"用引号引起来.

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?

推荐答案

"@ Model.Bla"应该做什么?

What is that "@Model.Bla" stuff supposed to do?

Razor语法的意思是简单地呈现页面模型的属性"Bla".这行:

That Razor syntax means simply, render the property "Bla" of the page model. This line:

@model TLDReporter.Models.TLDSalesReceiptCriteriaModel

指示页面模型的类型.您将必须找到控制器代码,以弄清楚该类的实例是如何返回(或不返回)的.您应该能够找到类似"XyzController"的类,并且该类具有返回"ActionResult"或类似内容的方法,该类具有以下内容:

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);

这篇关于为什么我的“替换参数"变成空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆