ASP.NET MVC razor: conditional attribute in HTML

后端 未结 7 1666
鱼传尺愫
鱼传尺愫 2020-12-02 15:21

Code below doesn\'t seems clean. Any suggestion to improve the code?

  • class=\
  • 7条回答
    •  遥遥无期
      2020-12-02 15:36

      MVC has conditional attributes built in...

      class="@myClass" } }>Content
      Content

      If @myClass is null, it just won't use the attribute at all...

      I know that may not quite solve your current issue, but it is noteworthy!

      http://weblogs.asp.net/jgalloway/archive/2012/02/16/asp-net-4-beta-released.aspx

    提交回复
    热议问题