【发布时间】:2017-01-30 15:04:28
【问题描述】:
我的部分观点是这样的
@Html.EditorFor(model => model.DirectorsEntity.ApplicationDate, new { @class = "form-control", @id="appdate" })
在我的 jquery 中我有:
var appdate = $("#appdate").val();
不幸的是,它以未定义的形式返回。
我将我的 EditorFor 更改为 TextBox,它可以工作,但我更喜欢使用 EditorFor。有谁知道为什么一个可以工作而另一个不行?
@Html.TextBoxFor(model => model.DirectorsEntity.ApplicationDate, new { @class = "form-control", @id="appdate" })
【问题讨论】:
-
因为
EditorFor()不允许您添加 html 属性,除非您使用 MVC-5.1 或更高版本,如果您是,那么它无论如何都不是正确的格式(参考骗子)。你的EditorFor()正在生成id="DirectorsEntity_ApplicationDate",所以只需使用var appdate = $("#"DirectorsEntity_ApplicationDate").val();
标签: jquery asp.net-mvc razor editorfor