asp.net mvc - IF ELSE html helper in razor view? -


i use if else statement in razor view. possible use if( html.helper ) something? or suggestion?

@using (html.beginform()) {     <table>              @for (int = 0; < model.count; i++)             {                 <tr>                     <td>                         @html.hiddenfor(m => m[i].question_id)                         @html.hiddenfor(m => m[i].type)                         @html.displayfor(m => m[i].question)                     </td>                 </tr>                 <tr>                     @if(@html.displayfor(m=> m[i].type =="info_text") **                     {                         <td>                               //do nothing                         </td>                                     }                     else                     {                      <td>                         @html.editorfor(m => m[i].answer)                     </td>                     }                 </tr>             }      </table> 

as mentioned in comment, can test value of m[i].type directly:

@if (m[i].type == "info_text") {   <td></td> } else {   <td>@html.editorfor(m => m[i].answer)</td> } 

the reason wouldn't test against value of displayfor returns mvchtmlstring, not simple type string or int. could if ever find need compare displayfor day (and makes make little more sense):

@if (html.displayfor(m => m[i].type) == new mvchtmlstring("info_text")) 

since you're in process of learning mvc, might interested in how can customize editorfor helper automatically: http://www.hanselman.com/blog/aspnetmvcdisplaytemplateandeditortemplatesforentityframeworkdbgeographyspatialtypes.aspx


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -