0

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))
    {
        return "<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.

1
  • anyway, use StringBuilder, not string concatenation. Commented May 31, 2011 at 13:50

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.