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:
what would be the right syntax for that?
thanks.
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>
what would be the right syntax for that?
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Not the cleanest way but hey, it worked.
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