简体   繁体   中英

rendering data- attributes in razors

I'm trying to render some data- attributes inside razor cshtml page

   <tr id="@{<text>bk</text>@f.Id}"
              data-time="@f.Time.ToString("ddd HH:mm")"
              data-bookid="@c.BookId"                                       
              @{ 
                 if (bookF > 0f) { 
                    <text>data-bookprice="@bookprice.ToString("0.00", CultureInfo.InvariantCulture)"</text>
                  }}

using this I'm getting compilation error

Line 182:WriteAttribute("id", Tuple.Create(" id=\\"", 1162), Tuple.Create("\\"", 1190)

removing this code without <text> attributes and using plain html works fine.

Try wrapping the code with brackets eg:

   <tr id="<text>bk</text>@f.Id"
              data-time="@{(f.Time.ToString("ddd HH:mm")")}"

etc..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM