javascript - asp.net _Layout.cshtml 仅在模型类型为 ______ 时加载脚本
问题描述
如果模型属于某种类型,如何仅在我的 _Layout.cshtml 中加载脚本?如果模型是我制作的自定义模型类型,我只希望我的布局加载脚本标签。
解决方案
你可以在你的视图中通过剃刀语法来做到这一点
@if(Model is <yourtypehere>)
{
<script>alert('this is my type')</script>
//or you can even
<script src="myjavascriptfilelocation"/>
}
推荐阅读
- reactjs - 我应该将组件中定义的所有函数包装在 useCallback 中吗?
- xslt - XSLT 中的日期格式转换
- c# - 从 Azure 存储中获取 blob 文件名的最快方法
- excel - 检查行中的条件,然后打印列值
- java - 当缺少消息键时,如何使 Spring Boot 默认为语言环境?
- python-3.x - 使用带有包含选项的 xpath 单击按钮
- ios - Xcode 中的优化级别
- python - 使用 tensorflow 在笔记本电脑上训练人工智能并在树莓派上执行
- ffmpeg - FFMPEG:RTSP 流冻结,但 FFMPEG 继续录制
- python - 如何使用python按日期对文件中的数据进行排序?