@{ @* Get a 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 }
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.
Unexpected whitespace when outputting .Count()
Hi all,
I'm trying to simply output the count of elements in a list in Razor by doing:
And it outputs the number as it should, but unfortunately for the 'frontend'ers' it creates a whitespace before the number, like this:
I've tried @Html.Raw(), .ToString().Trim(), but without any result.
Anyone know how to get rid of this whitespace? :-)
Thanks in advance.
Bo
Can you paste your code-block?
I think that Count() return Int so i guess the reason it is how you make the output
Hi gilad,
Thanks for your response :-)
My code is as simple as this:
I've also tried:
But it's the same :-)
Thanks again.
Bo
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:
I guess it is gonna outpot 8 without any whitespace.
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:
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
Hi Bo.
If this check also outputs with whitespace , maybe is in your html code...
Try this in your macro :
It is also output with whitespace?
Maybe there is some script that do this?
Hi gilad,
How strange is that: I tried to create a new razor macro with just:
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.
is working on a reply...