Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
I want to include the lines
$('#mod-progress').modal('hide');
window.progressBarActive = false;

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

What I have tried:

Don't know how to include js inside C# code.
Posted
Updated 20-Jan-17 10:34am
v2
Comments
[no name] 20-Jan-17 8:44am    
AFAIK, you don't. It wouldn't do you any good. C# runs on the server and javascript runs on the client.
Member 12958722 20-Jan-17 11:27am    
thank you.

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>
}
 
Share this answer
 
v2
Comments
Member 12958722 20-Jan-17 11:27am    
thank you.
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.
 
Share this answer
 
v2
Comments
Member 12958722 20-Jan-17 14:13pm    
Yes, thank you.
Adityakumar2318 5-Jun-17 9:53am    
You are welcome. If you liked my solution then please accept the solution. Please upvote it.
Quote:
How to include javascript code in C# class.
Short answer: you don't.
Languages are not designed to be mixed in source code, there is only very limited exceptions.
In C/C++, you can embed assembler code, C/C++ is designed for this.
SQL is very common, but you can see any query is just a string with no syntax checking, you get the surprises at runtime.

In your case, there is another problem, both languages don't run on same computer, one is server side, the other is client side.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900