ASP.NET 视如何增加一个类Html。EditorFor时的课程已经存在由于不显眼的js验证?

StackOverflow https://stackoverflow.com/questions/4272492

  •  28-09-2019
  •  | 
  •  

我想添加一个 Class 来的 EditorFor 帮助内部的的一个 EditorTemplate.

问题是,因为我使用 不显眼验证, ,所输入的元素已经具有类分配给它。

这里是我的EditorTemplate

@Inherits System.Web.Mvc.ViewUserControl(Of Nullable(Of Date))
@Html.TextBox("", If(Model.HasValue, String.Format("{0:MM/dd/yyyy}"), String.Empty), New With {.class = "datepicker"})

这里是输出

<input class="text-box single-line" id="BirthDate" name="BirthDate" type="text" value="08/08/1980" />

你可以在这里看到的 datepicker 类没有被加入,但"价值"已经正确的格式。

我基本上可以看到, EditorTemplate 是的工作,但是 Class 是不是被附加于其他类 <input> 元素。

做任何你知道怎么修这个?

有帮助吗?

解决方案

事实证明我不得不添加一个 <UIHint("Date")> 我的好友类。

一切都是正确的。

@ModelType Date?
@Html.TextBox("", If(Model.HasValue, String.Format("{0:MM/dd/yyyy}", Model), String.Empty), New With {.class = "datepicker"})

这里的原因UIHint.

默认的模板的名字是基于CLR类型的姓名,在这种情况下DateTime。"日期"是一个快捷的名称在VB,不真正式名称(如"int"C#是真正的快捷方式CLR的"Int32").

其他提示

尝试 通用标签

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top