C# 点击标签文本框是否被选中?

C# 点击标签文本框是否被选中?,c#,asp.net-mvc,C#,Asp.net Mvc,我在MVC应用程序中面临一些异常行为。我在视图中使用了文本框和标签 @Html.LabelFor(m => m.AddressLine1) @Html.TextBoxFor(m => m.AddressLine1, new { maxlength = 40, title = "Enter Address Line1" }) 在我的ViewModel中 [DisplayName("Address Line1")] [Required(ErrorMessage = "Please en

我在MVC应用程序中面临一些异常行为。我在视图中使用了文本框和标签

@Html.LabelFor(m => m.AddressLine1)
@Html.TextBoxFor(m => m.AddressLine1, new { maxlength = 40, title = "Enter Address Line1" })
在我的ViewModel中

[DisplayName("Address Line1")]
[Required(ErrorMessage = "Please enter Address Line1")]
public string AddressLine1 { get; set; }

在调试时,当我点击标签时,textbox被选中。请有人帮我解决,并告诉我为什么我会面临这样的问题。

这是标签的标准行为:

标记定义元素的标签

元素不会呈现为用户的任何特殊元素。 但是,它为鼠标用户提供了可用性改进,因为 如果用户单击
元素中的文本,它将切换 控制


我能停止这种行为吗?如果是,那怎么办?请告诉我不要使用label:
@m.AddressLine1
而不是
@Html.LabelFor(m=>m.AddressLine1)
。例如,编辑时,label将更改为文本框值,然后离开
LabelFor
并使用此解决方案停止标签选择控件:然后将其硬处理:
地址行1
这将100%工作,不会做任何事情。唯一的缺点是您必须直接更新html,而不是
ViewModel