Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Unable to get vanlue of DatePicker
posted

I am using the DatePicker to build a Query but I can't get the value of the component

I'm using MVC3 in combination with vb.net

below are my model controller and view

model:

Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
Imports System.Globalization
Imports Infragistics.Web.Mvc
Imports System.Linq

Public Class FilterPartialModel

Private bla As String

<Display(name:="Start date filter")> _
Public Property StartDateTime As DateTime

<Display(name:="End date filter")> _
Public Property EndDateTime As DateTime

<Display(name:="Select the sate you want to see")> _
Public Property StateName As String
Get
Return TrackingUser.Instance.NameStateFilter
End Get
Set(value As String)
TrackingUser.Instance.NameStateFilter = value
End Set
End Property

<Display(name:="State list")> _
Public Function States() As SelectList
Return New SelectList(createList)
End Function

Private Function createList() As Collections.IEnumerable
Dim col As New Collection
col.Add("All")
col.Add("Open")
col.Add("Pause")
col.Add("In progress")
col.Add("Closed")
Return col
End Function

End Class

controller:

Imports System.Diagnostics.CodeAnalysis
Imports System.Security.Principal
Imports System.Web.Routing

Namespace MvcApplication2
Public Class OverViewFilterPartialController
Inherits System.Web.Mvc.Controller

'
' GET: /OverViewFilterPartial

Function Index() As ActionResult
Return View()
End Function


<HttpPost()> _
Function Filter(ByVal model As FilterPartialModel) As ActionResult
Try
TrackingUser.Instance.StartDateFilter = model.StartDateTime
Catch ex As Exception
TrackingUser.Instance.StartDateFilter = DateTime.Now.AddYears(-1)
End Try
Try
TrackingUser.Instance.EndDateFilter = model.EndDateTime
Catch ex As Exception
TrackingUser.Instance.EndDateFilter = DateTime.Now
End Try
TrackingUser.Instance.NameStateFilter = model.StateName
Return RedirectToAction("OverView", "Home")
Return View()
End Function

End Class
End Namespace

view:

@Imports Infragistics.Web.Mvc
@ModelType MvcApplication2.FilterPartialModel

@Code
ViewData("Title") = "OverViewFilterPartial"
End Code

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>

<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@Using Html.BeginForm("Filter", "OverViewFilterPartial", FormMethod.Post)
@<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30%">
<div>
@Html.LabelFor(Function(m) m.StartDateTime)
@(Html.Infragistics.DatePickerFor(Function(m) m.StartDateTime).ID("StartDateTimePicker").Width(150).DateInputFormat("dateTime").Value(Model.StartDateTime).NullText("Enter Start Filter Date").ValidatorOptions(Function(m) m.AnimationShow(0).AnimationHide(0).OnBlur(False).OnChange(False).OnSubmit(False).KeepFocus(ValidatorKeepFocus.Always)).Render())

</div>
</td>
<td width="30%">
<div>
@Html.LabelFor(Function(m) m.EndDateTime)
@(Html.Infragistics.DatePickerFor(Function(m) m.EndDateTime).ID("EndDateTimePicker").Width(150).DateInputFormat("dateTime").Value(Model.EndDateTime).NullText("Enter End Filter Date").Render())

</div>
</td>
<td width="30%">
<div>
@If Model IsNot Nothing Then
@Html.LabelFor(Function(m) m.StateName)
@Html.DropDownListFor(Function(m) m.StateName, Model.States)
End If

</div>
</td>
<td width="10%" >
<div>
<p>
<input type="submit" name="Filter" value="Filter" />
</p>
</div>
</td>


</tr>


</table>

</div>

End Using

as soon as I press the filter button I get het value: #12:00:00 AM# instead of the date i entert, help please?

Best regards,

Daniel van Cann

  • 24497
    posted

    Hi Daniel,
    Within controller the model.StartDateTime and EndDateTime should provide values entered on client.

    Though, after a postback the editors on client will get their original values, because application sets Value after editors were created. The editor gets value from client within its creation which is DatePickerFor(...). All following chained statements override any current values, so, statement like ...Value(Model.StartDateTime)... will lock value of editor to model.StartDateTime. If that is what is intended, but problem is in get-value within controller, then try to figure out what causes that. For example, temporary remove validation, initial-Value statements, etc.