0

My razor function in my index.cshtml

@functions{
public void FillTheList(){
//some part of code
}
}

I need to run FillTheList()-same cshtml with - function

<script>
@{
FillTheList();
}
</script>

Javascript cannot run FillTheList() function this code.How to i fix it

1
  • Hey more... i have expanded my answer which will hopefully help you more. Commented Jan 6, 2018 at 10:21

1 Answer 1

1

You are getting confused. Razor is C# html templating syntax that runs on a web server. Javascript is a code which runs on a users browser. You can use Razor to write JavaScript out, just the same as you can use notepad to write javascript.

Sign up to request clarification or add additional context in comments.

3 Comments

I dont need return value.I just need run this func.But it didn't.I think this solution is not working
I am just giving you an example. What do you want your method to do? P.S func is a kind of C# delegate.
Exactly what @Harry said. Razor is an engine which allows you to create HTML using C# syntax. The Razor engine takes the cshtml file in your view and produces the resulting HTML which is sent to the browser as the response body. As such, the Razor syntax will be replace with HTML before it is served by your web-server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.