2017-11-18 85 views
-1

我想在@ Html.EditorFor中使用mvc中的文本占位符。我尝试了很多东西,甚至在谷歌搜索,但无论我得到的答案不工作。我很惊讶...... !!!最后我问问题。如何在mvc中使用占位符for editorfor?

我的占位符最新的代码是

@Html.EditorFor(model => model.ToEmail, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Your EmailID...!!!" } }) 

此代码还无法正常工作。

谢谢。

+0

代码是正确的。这应该会给你想要的输出。 –

+0

@Kumar_Vikas这就是为什么我惊讶,为什么它不工作。 –

+0

也许问题是与mvc版本https://stackoverflow.com/a/23478509/3467213 – pryashrma

回答

0

我有同样的问题,因为你,下面的代码在我的项目工作对我来说:

@Html.EditorFor(model => model.ToEmail, new { htmlAttributes = new {placeholder = @Html.DisplayNameFor(m=>m.ToEmail) } }) 
0

如果您需要添加HTML属性,你应该使用@HTML.TextBoxFor代替EditorFor和绑定值从价值属性即

@Html.TextBoxFor(model => model.ToEmail, new { @value = model.ToEmail, @class = "form-control", @placeholder = "Enter Your EmailID...!!!" }) 
+0

不要在使用HtmlHelper方法时设置'value'属性。 –