开发者

MVC Razor String Concat

开发者 https://www.devze.com 2023-02-27 21:20 出处:网络
I am using Razor to generate a form. I want to create HTML elements based on some value from it\'s model property.开发者_开发知识库

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


I think this should work for you:

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


another option:

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

精彩评论

暂无评论...
验证码 换一张
取 消