19

I am using Razor to generate a form. I want to create HTML elements based on some value from it's model property.

for example, if a model contains Id property, and I want to generate html tags as follows

<input type="hidden" name="1_chk" /> 
<input type="hidden" name="2_chk" />  
<input type="hidden" name="3_chk" />  

So I used the following syntax, and it failed. Can anyone help me out with this?

<input type="checkbox" name="@Id_chk" /> 

Thanks

2 Answers 2

50

I think this should work for you:

<input type="checkbox" name="@(Id)_chk" />
Sign up to request clarification or add additional context in comments.

Comments

10

another option:

<input type="checkbox" name="@(Id + "_chk")" />

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.