0

When I looked at the documentation of the EditorFor method from the MVC library I came across this method definition :

public static MvcHtmlString EditorFor<TModel, TValue> {
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    Object additionalViewData
}

It felt hard to understand for me but I think HTML helpers can be helpful so I want to understand and I also want to figure out its logic so that I can use it in other method definitions. I would be appreciated if you can help.

Edit: What can be a proper use of this method definition?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • 5
    What do/don't you know already? What, specifically, do you need help understanding? –  Aug 27 '14 at 14:33
  • Do you know about extension methods? That should explain the "this HtmlHelper html part of the method. – Steen Tøttrup Aug 27 '14 at 14:35
  • How can a method *definition* be too complicated? What is it your don't understand? Or You can [browse the source code for that method if it helps...](http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/Html/EditorExtensions.cs) – DGibbs Aug 27 '14 at 14:36
  • Have you read [this](http://www.pearson-and-steel.co.uk/how-to-use-the-html-editorfor-method/)? – crthompson Aug 27 '14 at 14:36
  • So i should give it a class as a parameter and then use this class to return an object – user3908357 Aug 27 '14 at 14:38
  • If you want to see some example usages of the method just search for some in Google. There are plenty out there. – Servy Aug 27 '14 at 14:49

1 Answers1

0

This is an extension method (which is why you see this and static). It takes two generic types (<TModel, TValue>) which you must specify on invoking the method, so that they can then be used/referred to throughout (including the other parameters e.g. HtmlHelper<TModel>). This method will return an object of type MvcHtmlString.

This is all you can gather from a signature. What it actually does and/or how it does it can only be told from it's contents.

Reading:

Extension methods:

http://msdn.microsoft.com/en-GB/library/bb383977.aspx

Generics:

http://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx