Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 29, 2012 @ 15:09
    Bo Damgaard Mortensen
    0

    Unexpected whitespace when outputting .Count()

    Hi all,

    I'm trying to simply output the count of elements in a list in Razor by doing:

    @myList.Count()

    And it outputs the number as it should, but unfortunately for the 'frontend'ers' it creates a whitespace before the number, like this:

    ( 8)

    I've tried @Html.Raw(), .ToString().Trim(), but without any result.

    Anyone know how to get rid of this whitespace? :-)

    Thanks in advance.

    Bo

     

  • gilad 185 posts 425 karma points
    May 29, 2012 @ 15:11
    gilad
    0

    Can you paste your code-block?

    I think that Count() return Int so i guess the reason it is how you make the output

     

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 29, 2012 @ 15:21
    Bo Damgaard Mortensen
    0

    Hi gilad,

    Thanks for your response :-)

    My code is as simple as this:

    @{
        @Get reference to the data access layer *@
        DbRecipe db new DbRecipe();
        
        @Get number of comments for this recipe *@
        var numOfComments db.GetNumberOfCommentsForRecipe(Model.Id);
        
        @Output to frontend *@
        @numOfComments
    }

    I've also tried:

    @numOfComments.ToString()

    But it's the same :-)

    Thanks again.

    Bo

  • gilad 185 posts 425 karma points
    May 29, 2012 @ 15:30
    gilad
    0

    Hi Bo.

    Maybe it is your function - GetNumberOfCommentsForRecipe ? 

     

     

    What type is it return?

    It is a macro? or inline razor?

    anyway - just for checking try to make thie:

    @{
        int aa = 8;
        @Html.Raw(aa)
    } 

    I guess it is gonna outpot 8 without any whitespace.


  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 29, 2012 @ 15:37
    Bo Damgaard Mortensen
    0

    Hi gilad,

    The GetNumberOfCommentsForRecipe() method is simply a method on my data access layer to get the number of comments for a given page (recipe), so it return an int.

    I've just tried the following:

    int test 8;  
    @Html.Raw(test.ToString())

    But it also outputs a whitespace :-/ And I've triple checked that there's no padding, margin, whitespace and/or what-so-ever in my markup/css.

    Thanks again :-)

    - Bo

  • gilad 185 posts 425 karma points
    May 29, 2012 @ 15:44
    gilad
    0

    Hi Bo.

    If this check also outputs with whitespace , maybe is in your html code... 

    Try this in your macro : 

    @{
        int aa = 8;
        <div>@aa</div>
    }

    It is also output with whitespace?

    Maybe there is some script that do this?

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 29, 2012 @ 15:51
    Bo Damgaard Mortensen
    0

    Hi gilad,

    How strange is that: I tried to create a new razor macro with just:

    @{
        int aa = 8;
        @aa
    }

    And put it in place of my CommentsCount razor macro and it gives no whitespace.

    What gives? :-) I've debugged and checked the output from my DAL method and it returns an integer just as if I set an int variable like above.

  • 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