1
Vote

[BUG] DateTime is missing when posting

description

[How to reproduce]

  1. create an asp.net mvc project.
    on a view page add the following code:
    <%=Html.Datepicker("date", DateTime.Now.ToShortDateString())%>
<!-- add code. and submit-->
  1. on controller part, on post method try to get the "date" from Request.Form ( Request.Form["date"] )
     

3. Run application.

When debugging application in pot method on controller side the "date" is not found in Request.Form.
 

[Solution]

DatePicker extender is creating an input HTML tag which add attributes: "id", "type", "value". But attribute "name" is missing after adding "name" attribute my problem was solve.
 
public static string Datepicker(this HtmlHelper htmlHelper, string id, string value, object dataPickerOptions, object htmlAttributes, bool withoutScript)
    {
       .............................................................................................. 
       // Create valid id
        builder.GenerateId(id);
 
        /// ADDED START
        builder.MergeAttribute("name", id);
        /// ADDED END
        .......................................................................................
 
Hope is help!
 
Radu.

comments