Html.TextBox is 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 ViewData dictionary inside the controller action and the helper will use this value when rendering the textbox (ViewData["foo"] = "bar").

Html.TextBoxFor is 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.TextBoxFor helper.

相关文章:

  • 2021-12-01
  • 2021-10-13
  • 2021-08-20
  • 2021-08-30
  • 2021-10-13
  • 2022-01-04
  • 2021-09-07
  • 2021-09-13
猜你喜欢
  • 2021-11-18
  • 2021-10-28
  • 2021-05-03
  • 2021-08-07
  • 2021-10-02
  • 2021-09-12
  • 2021-10-23
相关资源
相似解决方案