Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

razor : creating pinterest string

I'm trying to create a pinterest pin it button. Below is the code:

<a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.domain.name%2Fproduct%[email protected]&media=http%3A%2F%2Fwww.domain.name%2Fproduct%[email protected]&[email protected]" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
       <script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>

As you see there are three variables:

url : http%3A%2F%2Fwww.domain.name%2Fproduct%[email protected]

media: http%3A%2F%2Fwww.domain.name%2Fproduct%[email protected]

description: @Model.ProductDetails.ProductDescription

In all three variables some data is coming from ViewModel using @Model

But only @Model.ProductDetails.ProductDescription is working And the other two are not working maybe because they are part of a bigger string.

like image 959
Arnab Avatar asked May 06 '26 04:05

Arnab


1 Answers

The razor parser thinks that the first two values are email addresses or similar and so leaves them as plain text. In order to inform the parser that they should be evaluated you need to use an Explicit Expression, eg @(Model.Property), so your variables would be:

url : http%3A%2F%2Fwww.domain.name%2Fproduct%2F@(Model.ProductDetails.URLName)
media: http%3A%2F%2Fwww.domain.name%2Fproduct%2F@(Model.ProductDetails.Image)
description: @(Model.ProductDetails.ProductDescription)

And your snippet would be:

<a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.domain.name%2Fproduct%2F@(Model.ProductDetails.URLName)&media=http%3A%2F%2Fwww.domain.name%2Fproduct%2F@(Model.ProductDetails.Image)&description=@(Model.ProductDetails.ProductDescription)" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>

I generally keep Phil Haack's Razor Quick Reference guide bookmarked!

like image 114
Rich O'Kelly Avatar answered May 09 '26 01:05

Rich O'Kelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!