0

我正在尝试将占位符设置为 MVC 4 中的文本框或多行文本框。到目前为止它不起作用。

[Display(Name = "Location", Prompt = "Enter info related to Location")]
public string LocationDesc { get; set; }

和视图如下

@Html.EditorFor(model => model.LocationDesc , new { placeholder = "Enter info related to Location" })

占位符只需要显示一些信息,我很乐意在任何地方显示它(视图或模型)

我们正在使用 MVC4。

干杯

4

1 回答 1

1

You cannot use Placeholder attribute on @Html.EditorFor() in asp.net mvc,there are two solutions for your problem :

1.) You can make a custom attribute for @Html.EditorFor() a great article on this is there on stackoverflow link :- Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? and you can visit this link also http://aspadvice.com/blogs/kiran/archive/2009/11/29/Adding-html-attributes-support-for-Templates-2D00-ASP.Net-MVC-2.0-Beta_2D00_1.aspx

2.) Instead of @Html.EditorFor() you can use @Html.TextAreaFor()

于 2014-08-08T07:47:01.230 回答