0

I wrote a javascript function in which new row gets added in the table. For static data it is working fine, how to place Razor tags inside those javascript var

var count = "1";
var strHtml1 ="@Html.CheckBoxFor(x => x[count].isChecked)";
count++;

This line doesn't seem to work. How should I place the razor code inside the var and also the count [var] inside that razor code.

0

2 Answers 2

3

Here your count variable is javascript . Can you try to make whole count logic in razor and strHtml out like this ?

@{
var count = "1";
var strHtml1 =Html.CheckBoxFor(x => x[count].isChecked);
count++;
}
//and in js
var jsStrHmtl='@strHtml1';
Sign up to request clarification or add additional context in comments.

1 Comment

exactly what I was about to post.. we've done this before and it worked out fine.
0

Just use single quotes

var count = "1";
var strHtml1 ='@Html.CheckBoxFor(x => x[count].isChecked)';
count++;

If it is just the value of checkbox then you can get the value using jquery

var count = $('.count:checked').val(); 

Comments

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.