<asp:TextBox> Vs <input type=“text”> Vs Html.TextBox

不打扰是莪最后的温柔 提交于 2021-01-27 14:20:35

问题


I am working in asp.net application, adding functionalities like form elements, validation and populating data from DB.

  1. I can use ASP: controls but I am wondering is it possible to use HTML.TextBox or <input type="text">

  2. If I can use <input type="text" or Html.TextBox what are the pros and cons of using them versus using


回答1:


Forget about server side controls in ASP.NET MVC. Everything containing runat="server" is a big NO in ASP.NET MVC. Won't work in Razor anyways. There are no pros and cons. Server side controls should never be used so there's nothing to compare. Simply use HTML helpers such as Html.EditorFor and Html.TextBoxFor.




回答2:


If you're using ASP.NET MVC, then either the manual typing (<input type="text" />) or the helper extension (Html.TextBoxFor(x => x.SomeProperty)) are going to be your best bet, and it really depends on what you are planning on doing. If the control you are making has no property on your element, it can be a lot easier to simply hand code the input tag.

Never use <asp:Checkbox ID="blah" runat="server" /> in an MVC application.



来源:https://stackoverflow.com/questions/10401677/asptextbox-vs-input-type-text-vs-html-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!