difference between Html.TextBox and Html.TextBoxFor
2012-05-30 22:15
471 查看
Html.TextBoxis not strongly typed and it doesn't require a strongly typed view meaning that you can hardcode whatever name you want as first argument and provide it a value:
<%= Html.TextBox("foo", "some value") %>
You can set some value in the
ViewDatadictionary inside the controller action and the helper will use this value when rendering the textbox (
ViewData["foo"] = "bar").
Html.TextBoxForis requires a strongly typed view and uses the view model:
<%= Html.TextBoxFor(x => x.Foo) %>
The helper will use the lambda expression to infer the name and the value of the view model passed to the view.
And because it is a good practice to use strongly typed views and view models you should always use the
Html.TextBoxForhelper.
相关文章推荐
- difference between "create group for any added .." and "create folder references ..."
- Preparing for Application and Service Deployment-Differences Between the Storage Emulator and Window
- Difference Between ASP.NET Server Controls,HTML Server Controls and HTML Intrinsic Controls
- Difference between href and reload for refreshing in javascript
- [XHTML Tutorial] 走向XHTML标准 (3)(Differences Between XHTML And HTML)
- What is the difference between objectForKey and valueForKey?
- The Difference between write through and write back for cache
- [XHTML Tutorial] 走向XHTML标准 (3)(Differences Between XHTML And HTML)
- Difference to between COMPUTE STATISTICS and VALIDATE STRUCTURE for ANALYZE INDEX
- Difference Between Class.ForName() And ClassLoader.LoadClass() Methods In Java
- What is the difference between max-device-width and max-width for mobile web?
- Difference Between objectForKey and valueForKey in NSDictionary
- What is the difference between authorized_key and known_host file for SSH
- Difference between maven scope compile and provided for JAR packaging
- What’s the difference between Catia, SolidWorks and Inventor? Which one for me?
- SQL SERVER – Difference Between EXEC and EXECUTE vs EXEC() – Use EXEC/EXECUTE for SP always
- JavaScript: What's the difference between HTML attribute and DOM property?
- Difference Between Class.forName() and ClassLoader.loadClass()
- the differences between DataGrid and DataList in HTML View
- Difference Between objectForKey and valueForKey in NSDictionary