如何在C#类中包含javascript代码。 [英] How to include javascript code in C# class.

查看:78
本文介绍了如何在C#类中包含javascript代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括以下几行:

I want to include the lines

$('#mod-progress').modal('hide');
window.progressBarActive = false;


C#controller方法中的
。我如何实现它。



我尝试过:



不知道如何在C#代码中包含js。


in C# controller method. How do I achieve it.

What I have tried:

Don't know how to include js inside C# code.

推荐答案

('#mod-progress')。modal('hide');
window.progressBarActive = false;
('#mod-progress').modal('hide'); window.progressBarActive = false;


C#controller方法中的
。我如何实现它。



我尝试过:



不知道如何在C#代码中包含js。


in C# controller method. How do I achieve it.

What I have tried:

Don't know how to include js inside C# code.


您不能在控制器代码中包含js,您必须了解网页的生命周期。您的服务器代码运行并生成html,一旦您的服务器代码运行,html就会传递给浏览器使用,那就是执行js的时候。如果您希望js出现在您的页面中,那么您将其放在视图中,或以其他方式将其注入页面。因此,如果您只想在某些条件下使用js,那么您的视图将具有类似



You can't include js in your controller code, you have to understand the lifecycle of a web page. Your server code runs and generates html, and once your server code has ran that html is passed to the browser to use and that is when js is executed. If you want js to appear in your page then you put it in the view, or inject it into the page some other way. So if you only want your js on certain conditions then your view would have something like

@if (someCondition)
{
<script>
..
</script>
}


Java Script和C#是两种不同的编程语言。



Java脚本是客户端语言,Java脚本仅在浏览器的上下文中运行。

Java脚本不提供任何执行环境,因此它始终在浏览器上下文中运行。



C#是服务器端语言,它运行并生成html。

你不能在控制器中添加JS文件。



F-ES Sitecore是对的,你只能在视图中使用Java Script。



希望它能为你提供一些帮助。
Java Script and C# is two different programming language.

Java Script is client side language, Java Script runs in the context of browser only.
Java Script dont provide any execution environment so it always runs in browser context.

C# is server side language where it runs and generate the html.
You cannot add JS file in controller.

F-ES Sitecore is right, you can use Java Script in view only.

Hope it makes some point for you.


这篇关于如何在C#类中包含javascript代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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