Setting JQWidgets Datetime Picker value on server side with Asp.Net MVC

1.5k Views Asked by At

After creating a Datetime picker control using JQWidgets, you can set value to that control in this manner:

$("#jqxdatetimeinput").jqxDateTimeInput(‘setDate’, new Date(2010, 1, 1));

It's fine but in my case, I use Asp.Net MVC with Razor and the data retrieved from my repository is available while rendering my view.

I want to be able to set the date value to my Datetime picker at that moment; when rendering the view at server side.

Note that with JQWidgets, for creating a Datetime picker, you must declare a div element with an id and then call a function to transform it in Datetime picker. This is the reason why I'm not able to set the date value from my model to an html element.

I don't want to put a script block and accessing my model in this block to set the Datetime picker like that:

<script>
  $("#MyDivElementId").jqxDateTimeInput('setDate', @Model.Today);
</script>

I also want a solution without Knockout.js; I Love Knockout.js but in my case, simple model binding solution is enough.

Anyone have a better solution?

1

There are 1 best solutions below

1
On

$("#divselector").jqxDateTimeInput({ width: '150px', height: '25px', formatString: 'dd/MM/yyyy', theme: theme, value: new Date(@Model.ValidFrom.Year, @Model.ValidFrom.Month, @Model.ValidFrom.Day) });