小编Tom*_*Tom的帖子

ASP.NET MVC 2:DateTime的禁用TextBox返回null

我遇到了绑定到禁用的文本框的DateTime的恼人绑定行为.它总是返回null.

我的模型有DateTime?StartDate属性......我也尝试过DateTime StartDate(没有'?').

我尝试过以下方法:

尝试#1:

<%: Html.TextBoxFor(model => model.StartDate, new { @disabled="true" })%>
Run Code Online (Sandbox Code Playgroud)

尝试#2:

<%: Html.EditorFor(model => model.StartDate, "DateDisabled")%>
Run Code Online (Sandbox Code Playgroud)

其中DateDisabled是这样定义的局部视图:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
<%: Html.TextBox("", Model.HasValue ? Model.Value.ToShortDateString() : "", new { @class = "text-box-short-disabled", @disabled = "true" })%>
Run Code Online (Sandbox Code Playgroud)

我的所有尝试都返回一个空值.我错过了什么吗?还是一个解决方法?

asp.net-mvc-2

3
推荐指数
1
解决办法
3540
查看次数

标签 统计

asp.net-mvc-2 ×1