What is difference between textboxfor and editorfor method in mvc with example. [Resolved]

Posted by Kumarkrishna184 under ASP.NET MVC on 12/8/2015 | Points: 10 | Views : 8470 | Status : [Member] | Replies : 3
What is difference between textboxfor and editorfor method in mvc?

Thanks and Regards,
Krishna Kumar



Responses

Posted by: Sheonarayan on: 12/8/2015 [Administrator] HonoraryPlatinum | Points: 50

Up
1
Down

Resolved
TextBoxFor renders a text box for a particular field of the model in the view irrespective of the type of field. By default it considers the field as string type.

EditorFor renders different html form controls based on type of field of the model. For example, if the field type is

string - renders textbox,
boolean - renders checkbox
datetime - renders input type="datetime" textbox
int - renders intput type="number" textbox

The EditorFor method is very intelligent and it has ability to adapt its output based on field type, so it's dynamic in nature. You have even the ability to change the behavior of the EditorFor for certain field types. Read this article http://www.dotnetfunda.com/articles/show/2924/how-to-control-the-output-of-htmleditorfor-in-aspnet-mvc

If you want to know how to render a TextArea using EditorFor, read this post http://techfunda.com/Howto/asp-net-mvc/408/textarea-with-html-editorfor

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/8/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
DNF has already an answer for this http://www.dotnetfunda.com/interviews/show/8702/what-is-the-difference-between-htmleditorfor-and-htmltextboxfor-in-asp provided by Sheo Sir.

Just to add a little to it,

The big advantage of using EditFor is that if the datatype of the property in the model change, we need not to change anything in the view. EditFor will take care of the HTML markup by itself.

Hope this helps.

--
Thanks & Regards,
RNA Team

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 12/9/2015 [Member] Starter | Points: 25

Up
0
Down
Thanks sir...

Thanks and Regards,
Krishna Kumar

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response