I am currently browsing the source code of asp.net mvc 3 I just downloaded from codeplex. I'm particularly interested in seeing the source code of strongly typed Helper methods like TextBoxFor and DropDownListFor but failed to locate them in InputExtensions.cs and elsewhere.
Would someone point out where I can find required code? My purpose is to see how these helper methods add Html 5's data-* attributes to different input elements on the form.
The HtmlHelper class includes two extension methods TextBox() and TextBoxFor<TModel, TProperty>() that renders the HTML textbox control <input type="text"> in the razor view. It is recommended to use the generic TextBoxFor<TModel, TProperty>() method, which is less error prons and performs fast.
The TextBox for the Name value is created using Html. TextBoxFor function while the TextBox for the Mobile Number value is created using Html. TextBox helper function. The MaxLength of both the TextBoxes is set using the HTML MaxLength attribute using the HtmlAttributes parameter in Html.
IMO the main difference is that Textbox is not strongly typed. TextboxFor take a lambda as a parameter that tell the helper the with element of the model to use in a typed view. You can do the same things with both, but you should use typed views and TextboxFor when possible.
You don't need to download the source code or use reflector extensions.
If you "go to definition" (F12), you should see the file metadata, which is the summarized method declarations. From there, hover over the tab, and you should see the (local) file path where the method came from, which also corresponds to the namespace. With that, you'll be able to look it up from the MVC source code on Codeplex:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/5cb74eb3b2f3#src/System.Web.Mvc/Html/InputExtensions.cs
Get reflector (version 6. should be somewhere available for free), open System.Web.Mvc.dll
and search for InputExtensions
or
Get mvc source code, open in visual studio, and search for InputExtensions
edit: misread the question..
I guess you are looking for InputExtensions.cs line: 371
tagBuilder.MergeAttributes(htmlHelper.GetUnobtrusiveValidationAttributes(name, metadata));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With