Remove default ID attribute from HTML helpers in ASP.NET MVC

前端 未结 2 1153
攒了一身酷
攒了一身酷 2021-01-13 14:40

By default, MVC\'s input html helpers generate \"id\" and \"name\" with the same value. In my case i do not need the id, and when i do, I always enter a custom value. Auto g

2条回答
  •  有刺的猬
    2021-01-13 15:11

    I don't believe you can override the default behavior of the HTML Helpers... but can give some bits of advice.

    I'm not worried about extra "id" normally, as proper CSS structure and convention can help to prevent that. Where there can be conflict, send in a new { id = "foo", name = "foo" }.

    I seriously doubt that the "id = myfield" characters are going to add up to much. If you're interested in compression, you could take a look at Combres: (http://combres.codeplex.com/).

    Outside of this, the solution may be to create your own HTML helpers, which can override the basic ones, passing in your new { id = "" } (Haven't tested that.)

    Hope that helps.

提交回复
热议问题