【问题标题】:How can I put an @Html tag like editorfor inside an input with type email?如何将@Html 标签(如editorfor)放入电子邮件类型的输入中?
【发布时间】:2014-10-06 19:33:57
【问题描述】:

为什么我不能像这样将输入放在我的@Html.EditorFor 周围

<input id="email" type="email" class="form-control" id="inputEmail3" placeholder="Email">
@Html.EditorFor(model => model.Email)
</input>

我想要做的是绑定(?)电子邮件字段到我的数据库。

试过这个:

<input id="email" type="email" class="form-control" id="inputEmail3" placeholder="Email"
@Html.EditorFor(model => model.Email)
>

这在某种程度上是可行的,但 > 标记会显示在网页上。

关于如何解决这个问题的任何提示?

【问题讨论】:

  • 不确定我是否理解 - @Html.EditorFor 输入...由于它是模型的一部分,它将与表单一起提交。

标签: c# html sql visual-studio-2012


【解决方案1】:

您可以在 editorFor 字段中添加所需的 html 属性,如下所示:

@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control", placeholder = "Email" } })

您不希望 EditorFor 周围有输入表单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-28
    • 2020-06-08
    • 2021-04-17
    • 2017-12-03
    • 1970-01-01
    • 2016-06-26
    • 2013-05-17
    • 2017-09-21
    相关资源
    最近更新 更多