ID generation for HTML elements in ASP.NET MVC

后端 未结 4 961
刺人心
刺人心 2021-02-19 08:08

I need to generate unique identifiers for html elements in asp.net mvc application. In classic asp.net i could use

%>
         


        
4条回答
  •  野的像风
    2021-02-19 08:19

    There is no single solution to this.

    You need to modify your code to generate IDs based on whatever is generating the elements.

    For example, if you're looping over rows from a database, you can use the rows' primary keys to generate IDs.

    Alternatively, you can eschew IDs altogether and use non-unique classes. (this is especially convenient with jQuery and descendant selectors)

提交回复
热议问题