开发者

Jquery datepicker value on Controller action method

开发者 https://www.devze.com 2023-03-09 18:07 出处:网络
I\'ve created a extension method of Jquery datepicker, below are the source code. public static string DatePicker(this HtmlHelper htmlHelper, string name, DateTime? value)

I've created a extension method of Jquery datepicker, below are the source code.

public static string DatePicker(this HtmlHelper htmlHelper, string name, DateTime? value)
{
    if (!string.IsNullOrEmpty(name))
    {
        开发者_如何学Goreturn "<script type=\"text/javascript\">"
               + "$(function() {"
               + "$(\"#" + name +
               "\").datepicker({changeMonth: true,changeYear: true, dateFormat: 'dd/mm/yy', duration: 0});"
               + "});"
               + "</script>"
               + "<input type=\"text\" size=\"10\" value=\""
               + FormattedDate(value)
               + "\" id=\""
               + name.Replace('.', '_')
               + "\" name=\""
               + name + "\"/>";
    }

    return string.Empty;
}

I have used the above extension method in the View.

<div class="editor-label">
    @Html.LabelFor(model => model.Committee.AppointedDate)
</div>
<div class="editor-field">
    @Html.Raw(Html.DatePicker("CommitteeAppointedDate", Model.Committee.AppointedDate))
    @Html.ValidationMessageFor(model => Model.Committee.AppointedDate)
</div>

When I click on submit button, the view model which is holding above appointed date is showing DateTime.MinValue at the controller action method.

Please let us know what's wrong with the above code.


The short answer is: because your input name should be "Committee.AppointedDate" but you pass "CommitteeAppointedDate".

0

精彩评论

暂无评论...
验证码 换一张
取 消