Razor syntax inside attributes of html elements (ASP MVC 3)

前端 未结 1 1294
情歌与酒
情歌与酒 2021-01-31 01:13

I have a table with repeating customer rows, I would like to add the customer ID to the ID attribute of my table rows like this:



        
1条回答
  •  广开言路
    2021-01-31 02:09

    have you tried row@(c.id)?

    The actual reason why this doesn't work is because your row@c.id matches the regex for an email address. So the parser assumes it's an email and not actually an attempt to call code. The reason row@{c.id} doesn't work is because the @{} doesn't output and is meant to contain blocks of code.

    When in doubt you should use @() as it will force what's contained between the () to be parsed as code.

    0 讨论(0)
提交回复
热议问题