Skip to content Skip to sidebar Skip to footer

Pass C# Parameters To Js

I have a C#-MVC project. I want to refresh the page every X second - I put in the cshtml file the code: b

Solution 1:

Razor doesn't care if it's outputting HTML or javascript, so you could do:

<scripttype="text/JavaScript">
   timedRefresh(@(ViewBag.Seconds));
</script>

Solution 2:

If you are using the Razor syntax it can be done like this:

<scripttype="text/JavaScript">
  timedRefresh(@(ViewBag.Seconds));
</script>

The IntelliSense may report an error or warning, but it works anyway.

Solution 3:

It's pretty easy

<scripttype="text/JavaScript">
   timedRefresh(@ViewBag.Seconds);
</script>

Solution 4:

You can use an Action too. like this:

<scripttype="text/JavaScript">timedRefresh(@(Html.Action("Action","Controller")));
</script>

Post a Comment for "Pass C# Parameters To Js"