【问题标题】:replacing string with space in razor用剃刀中的空格替换字符串
【发布时间】:2014-01-30 17:33:02
【问题描述】:

我正在从复选框列表中将一些值放入我的 div 类中。 When one check box is selected it works as it should be but when two or more check boxes are selected it puts the " , " in between each value when the code is executed e.g Class="class1,class2 element".所以问题是,我怎样才能用两个类之间的空格替换“,”?以下是我的代码:

@{
var playerHref="http://player.vimeo.com/video/";
}
<!--gallery start-->
<div id="container" class="grid_12 isotope">
  @foreach (LoopItem i in GetLoop("ItemPublisher:Items.List")){

  <div id="box" class="@i.GetValue("ItemPublisher:Item.checkboxes") element">

    <a href="@playerHref@i.GetValue("itempublisher:Item.Vimeoid")" rel="Shadowbox;height=540;width=960" target="_blank">
      <img id="box-img" src="@i.GetValue("ItemPublisher:Item.GalleryImage")" title="play" alt="play">
      </a>
  </div>
    }
</div>
<!--gallery ends-->

【问题讨论】:

    标签: c# razor str-replace


    【解决方案1】:

    像这样替换 div#box 的类:

    <div id="box" class="@i.GetValue("ItemPublisher:Item.checkboxes").ToString().Replace(',',' ') element">
        ...
    </div>
    

    【讨论】:

      【解决方案2】:

      我在想这样的事情:

      ItemPublisher:Item.checkboxes.Replace(',',' ');
      

      或许

      ItemPublisher:Item.checkboxes.ToString().Replace(',',' ');
      

      终于

      @i.GetValue("ItemPublisher:Item.checkboxes").Replace(',',' ')
      

      希望其中一个可以工作

      【讨论】:

        【解决方案3】:

        试试这个方法

        @i.Replace(" ", ",")
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-05-09
          • 1970-01-01
          • 1970-01-01
          • 2015-08-03
          • 1970-01-01
          • 2018-12-01
          • 1970-01-01
          • 2020-12-19
          相关资源
          最近更新 更多