[显示(提示MVC3 [英] [Display(Prompt MVC3

查看:89
本文介绍了[显示(提示MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的模型,所以我可以用
@ Html.EditorFor(E => e.publicationTitle)并将它显示一个提示的水印。

I am trying to setup my model so I can use the @Html.EditorFor(e => e.publicationTitle) and have it show a Watermark with a hint.

目前我做

@Html.LabelFor(e => e.PublicationTitle) @Html.TextBox("PublicationTitle",tempTitle.ToString(), new { style = "width:350px", placeholder = "Put title here" })
       @Html.ValidationMessageFor(e => e.PublicationTitle)

我发现,你可以把一个 [显示(提示=在​​这里输入标题)] 在我的模型

但它没有显示在我出于某种原因认为了。

but it is not showing up in my view for some reason.

在一个侧面说明。我曾尝试遵循这个职位的说明
<一href=\"http://stackoverflow.com/questions/5824124/html5-placeholders-with-net-mvc-3-razor-editorfor-extension\">Html5使用.NET MVC 3剃须刀EditorFor扩展占位符?

On a side note. I did try to follow the instructions from this post Html5 Placeholders with .NET MVC 3 Razor EditorFor extension?

在这篇文章的结尾说,它改变了〜/查看/共享/ EditorTemplates / String.cshtml文件,但该文件没有位于我的项目。

At the end of this post it says to change the ~/Views/Shared/EditorTemplates/String.cshtml file but this file is not located in my project.

任何提示将AP preciated。谢谢你在前进。

Any hints would be appreciated. Thank you in advance.

跟进!

阿MVC3的乐趣。很显然,一旦你明白是怎么回事上述职位回答了这个问题。如果您在〜/查看/共享/文件夹中创建EditorTemplates / String.cshtml文件,那么它就会使用这个模板为您editfor框。

Ah the joys of MVC3. Apparently the above post answers the question once you understand what is going on. If you create the EditorTemplates/String.cshtml file in your ~/Views/Shared/ folder then it will use this template for your editfor boxes.

最后的答案要简明扼要别人看下面将要公布。

Final Answer to be concise for others looking will be posted below.

推荐答案

在你的控制器,你需要做以下

In your controller you need to do the following

[Display(Prompt="First Name Goes Here",Name="First Name")]
[StringLength(100,ErrorMessage="First Name may not be longer than 100 characters")]
public string AuthFirstName { get; set; }

提示符=这是会显示下显示的是将要创建的水印。

The Prompt="This is what will display" under display is the watermark that will be created.

然后,你将需要下创建文件夹EditorTemplates〜/查看/共享整个路径将是〜/查看/共享/ EditorTemplates /

Then you will need to create the folder "EditorTemplates" under ~/Views/Shared the entire path will be ~/Views/Shared/EditorTemplates/

然后创建该文件String.cshtml,并将以下code在它

Then create the file String.cshtml and place the following code in it

@Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue, new { @class="text-box single-line", placeholder = ViewData.ModelMetadata.Watermark })

更详细的信息,可以在张贴tugberk链接找到(<一个href=\"http://stackoverflow.com/questions/5824124/html5-placeholders-with-net-mvc-3-razor-editorfor-extension\">SO问题和<一个href=\"http://stackoverflow.com/questions/5824124/html5-placeholders-with-net-mvc-3-razor-editorfor-extension/6578465#6578465\">SO回答)。

这篇关于[显示(提示MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆