有剃刀文本框默认值消失

Beg*_*ner 1 textbox razor

我有一个带有两个文本框的表单.我想要的是当用户点击文本框时默认值消失.我正在使用剃须刀所以不确定如何添加我认为我需要的onfocus事件.

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "newsletterform" }))
{
    @Html.TextBoxFor(m => m.Name, new { @Value = "Name"})

    @Html.TextBoxFor(m => m.Email, new { @Value = "Email"})

    <input type="submit" class="newsletterGo" value="Go" />
}  
Run Code Online (Sandbox Code Playgroud)

Ada*_*gan 8

您可以使用占位符属性.它的一个例子是本页顶部的搜索框

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "newsletterform" }))
{
    @Html.TextBoxFor(m => m.Name, new { placeholder = "Default Name"})

    @Html.TextBoxFor(m => m.Email, new { placeholder = "person@example.com"})

    <input type="submit" class="newsletterGo" value="Go" />
}  
Run Code Online (Sandbox Code Playgroud)

此外,您不需要指定@Value属性.HTML帮助程序负责为您设置输入值.