Link to home
Start Free TrialLog in
Avatar of moshik008
moshik008

asked on

Mixing Javascript and C#

HI Experts,

in a Razor View I need the INDEX of the loop mixed in a C# syntax something like:

 
<script type="text/javascript">
...
 $.getJSON("/Controller/Action", { id: val }, function (data) {
           $.each(data, function (index, item) {
                   divbody +=    '<input id="' + selected_id + '" checked="@Model.PaymentTyp[index].Selected" type="checkbox" >' 
            });
 });
...
</script>

Open in new window


what would be the right syntax for that?

thanks.
Avatar of Shalom Carmel
Shalom Carmel
Flag of Israel image

Without diving too deep into your code, it seems that you are on the correct path.

C# is executed server side in IIS. For the C# code, Javascript is just text it outputs.
Javascript is executed client side in the browser. For the Javascript code, C# is completely unknown and transparent.

It is your responsibility to write the C# code that prints the correct JS and HTML.

Sometimes things don't work properly, and that's when you will ask EE for help.

Cheers
ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of moshik008
moshik008

ASKER

Not the cleanest way but hey, it worked.