Html.Textbox VS Html.TextboxFor [英] Html.Textbox VS Html.TextboxFor

查看:160
本文介绍了Html.Textbox VS Html.TextboxFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Html.Textbox之间的差异,Html.TextboxFor?

What is the difference between Html.Textbox and Html.TextboxFor?

推荐答案

最后他们都产生相同的HTML,但的 Html.TextBoxFor()是强类型,其中作为 Html.TextBox ISN吨。

Ultimately they both produce the same HTML but Html.TextBoxFor() is strongly typed where as Html.TextBox isn't.

1:  @Html.TextBox("Name")
2:  Html.TextBoxFor(m => m.Name)

都将产生

<input id="Name" name="Name" type="text" />

那么,是什么在使用术语的意思?

So what does that mean in terms of use?

一般两件事情:


  1. 键入的 TextBoxFor 将为您生成您的输入名称。这通常只是属性名称,但对于复杂类型的属性可以包括下划线,如CUSTOMER_NAME

  2. 使用输入 TextBoxFor 版本将允许你使用编译时检查。所以,如果你改变你的模型,那么你可以检查是否有你的观点的错误。

  1. The typed TextBoxFor will generate your input names for you. This is usually just the property name but for properties of complex types can include an underscore such as 'customer_name'
  2. Using the typed TextBoxFor version will allow you to use compile time checking. So if you change your model then you can check whether there are any errors in your views.

这被普遍认为是更好的做法是使用人的添加了MVC2

It is generally regarded as better practice to use the strongly typed versions of the HtmlHelpers that were added in MVC2.

这篇关于Html.Textbox VS Html.TextboxFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆