.net 在用户控件mvc中获取空值

.net 在用户控件mvc中获取空值,.net,asp.net-mvc,asp.net-mvc-3,user-controls,.net,Asp.net Mvc,Asp.net Mvc 3,User Controls,我正在尝试添加用户控件的文本框日历 我的观点 @Html.Partial("~/Views/Shared/EditorTemplates/DateTime.ascx", "FromDate"); 我的用户控件 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %> <%= Html.TextBox(ViewData.ModelMetadata.Propert

我正在尝试添加用户控件的文本框日历

我的观点

  @Html.Partial("~/Views/Shared/EditorTemplates/DateTime.ascx", "FromDate");
我的用户控件

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %>

<%= Html.TextBox(ViewData.ModelMetadata.PropertyName, new { @class="datepicker"} )%>

<script type="text/javascript">
$(document).ready(function () {
    $('.datepicker').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'mm-dd-yy',
        showButtonPanel: true,
        gotoCurrent: true
    });
});
错误消息

Value cannot be null or empty.
Parameter name: name
请帮助我获取从视图传递到用户控件的值

我想在此用户控件的同一页上使用多次。
如果有任何其他方式喜欢此功能,也会很有帮助。

使用EditorFor代替部分查看

这样称呼它:
m.PropertyName)%>

如果您想以适当的方式使用此示例

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>


 <%= Html.TextBox("", (Model.HasValue ? Model.Value.ToString("dd-MM-yyyy") : string.Empty), new { @class = "datepicker" }) %>


<script type="text/javascript">
    $(document).ready(function() {
        $('.datepicker').datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'mm-dd-yy',
    showButtonPanel: true,
    gotoCurrent: true
});
    });
</script>

$(文档).ready(函数(){
$('.datepicker').datepicker({
变化月:对,
变化年:是的,
日期格式:“年月日”,
showButtonPanel:是的,
gotoCurrent:对
});
});

我使用了您的用户控件,但模型的值仍然为空。您是否初始化了“动作中的模型”方法?您在哪里得到错误?在视图页面中调用EditorFor()或在EditorFor页面中?请不要介意我是mvc新手如果我使用EditorFor(),那么它将如何调用用户控件请解释我应该如何使用它一步一步地设置或给我相同的参考“好”。请看这个基本样品。和
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>


 <%= Html.TextBox("", (Model.HasValue ? Model.Value.ToString("dd-MM-yyyy") : string.Empty), new { @class = "datepicker" }) %>


<script type="text/javascript">
    $(document).ready(function() {
        $('.datepicker').datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'mm-dd-yy',
    showButtonPanel: true,
    gotoCurrent: true
});
    });
</script>