How do I conditionally show a field in ASP.NET MVC Razor?

后端 未结 5 1044
逝去的感伤
逝去的感伤 2021-02-05 17:11

I am very new to C# and ASP.NET MVC Razor. I want to show a field in my view if the field is not blank.

Code



        
5条回答
  •  醉话见心
    2021-02-05 17:41

    If it is very complicated logic then use like this:

    var trId = "";
    if(Model[i].FeeType == (int)FeeTypeEnum.LateFee  
        || Model[i].FeeType == (int)FeeTypeEnum.WaivedFee)
    {        
        trId=String.Format("{0}_{1}", @Model[i].ProductId, @Model[i].FeeType);
    }
    else
    {
       trId = @Model[i].ProductId.ToString();
    }  
    
    
      
    

提交回复
热议问题