Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between TextBoxFor and EditorFor in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.14k
    Comment on it

    These two are strongly-typed HTML helper methods and uses lambda expressions when referencing models passed to a view template.


    TextBoxFor will always show the textbox element no matter which kind of property we are binding it with. But EditorFor is much flexible in this case as it decides which element will be more suitable to show the property. Suppose we have a boolean property bind with EditorFor then to render this property in view, we can either use CheckBoxFor or EditorFor. Both will generate the same html.


    When we are sure that the html to be rendered will be simple input element (<input type="text" ...) in that case we can use TextBoxFor without thinking too much. But there are cases when we want to customize the way our element gets rendered, in such cases we can go for EditorFor and specify the template we want to show after it renders in html form.


    The advantage of using EditorFor is that, in future suppose we change the datatype of a property then we don't need to change anything in the view as the EditorFor will be updating the view automatically.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: