简体   繁体   English

TypeScript:该变量在MVC页面上定义

[英]TypeScript: the variable is defined on the MVC page

How can I make TypeScript aware that the Variable is defined in the cshtml file? 如何使TypeScript知道在cshtml文件中定义了变量? Can I add a reference inside the ts file? 我可以在ts文件中添加参考吗?

You can do this in a TypeScript file or a .d.ts file: 您可以在TypeScript文件或.d.ts文件中执行此操作:

declare var fromMvc: string;

This doesn't produce any code, but it makes the compiler aware that a variable with the name "fromMvc" exists. 这不会产生任何代码,但是会使编译器意识到存在名称为“ fromMvc”的变量。 After declaring that you can use it like a normal variable. 在声明可以像普通变量一样使用它之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查变量是否在 Typescript 中定义? - Check if variable is defined in Typescript? TypeScript + Vue 3 - ReferenceError:未定义变量 - TypeScript + Vue 3 - ReferenceError: variable is not defined 部分视图中的Javascript函数无法访问页面中定义的Javascript变量(MVC 3) - Javascript function in Partial view can't access Javascript variable defined in page (MVC 3) 变量在一个 function 中定义,在另一个 typescript 中未定义 - variable defined in one function and undefined in other typescript 从html页面访问js中定义的变量? - Access a variable defined in a js , from an html page? 在一页上设置变量并检查是否在另一页上定义了该变量 - setting a variable on one page and checking if it was defined on another 如何将type添加到使用typescript for中定义的变量中? - How can I add type to a variable defined in a for with typescript? Typescript:有没有办法检查变量是否是具有嵌套属性的接口定义的对象? - Typescript: Is there a way to check if a variable is an interface-defined object with nested properties? TypeScript和MVC - TypeScript and MVC 需要使用 JQuery - MVC2 中“控制”页面中定义的 Class - Need to use the Class defined in 'Control' page in JQuery - MVC2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM