Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Asna Ahamed 1 post 21 karma points
    Nov 02, 2013 @ 07:25
    Asna Ahamed
    0

    access razor variable values in jQuery

    hi,

     I am trying to get the values of a razor variable @item.name.It contains two names:name1 and name2.But when i use the following code i am getting only the first value ie,name1 in the javascript variable'nameVariable'

    foreach (var item in CurrentPage.Children().Where("Visible"))

    {

    @item.name

     

    @logoMediaItem.Name

    <script type="text/javascript"><!--
    </p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">           </span></p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">           </span>$(".image").hover(function()</p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">           </span>{</p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">           </span>var nameVariable=$("name").html();</p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">           </span>$(".nameDiv").html(nameVariable);</p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">           </span>});</p>
    
    <p><span style="white-space: pre;" mce_style="white-space: pre;">   </span>
    // --></script>

     

     }

    the div 'nameDiv' is repeating two times with the same value.I checked the values of  @item.name ,it displays the two values but only first name is pushing into the 'nameVariable'.How can I get the solution??

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 02, 2013 @ 07:47
    Fuji Kusaka
    0

    Hi ,

    Are you using a textString for the name1 and name 2 ? Or are you using the multiple textString from uComponents  ?.

    If so try doing something like this

    @if(Item.HasValue("yourAlias") && Item.GetProperty("yourAlias").Value != String.Empty){
    foreach(var t in Item.yourAlias){
    @t.InnerText <br />
      }
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies