c# - Appending variable in for loop to mvc4 razor helper -


i have number of fields in model named such model.var_1, model.var_2, ... model.var_30.

i trying put these in table using loop so.

<table>             <tr>                 <th>category</th>                 <th>description</th>                 @for (int = 1; <= model.total; i++)                 {                     <th class="ali_day@(i)">day @i</th>                 }             </tr>             <tr>                 <th>intubated</th>                 <th></th>                 @for (int = 1; <= model.total; i++)                 {                 <th>@html.editorfor(model => model.var_@(i))                     @html.validationmessagefor(model => model.var_@(i))</th>                 }             </tr>         </table> 

however, var_@(i) doesn't seem valid. there way append loop counter can variable name while using html helper?

use editor helper overload takes string, way can use string concatenation create variable name.

@html.editor("var_" + i) 

and same validation message

@html.validationmessage("var_" + i) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -