Problems igDatePicker
Hi,
I use jQuery igDatePicker in MVC3 Razor vbhtml according to the following example:
http://localhost:1027/samplesbrowser/date-picker
And I get 2 problems:
a) the datepicker headline with the month name and the 2 symbols "<" (previous month) and ">" (next month) is missing.
I do not know, if a java script reference is missing there or something else.
b) I need to transfer the chosen datepicker value to my controller class.
For usual textboxes you can use the "name"-Attribut as parameter in the controller class: e.g.
In the view: @Html.TextBox("txtDatum", Now.Day & "." & Now.Month & "." & Now.Year)
And in the controller class: Function Index(txtDatum As String) As ViewResult
So the value of "txtDatum" is tranferred to the controller class.
But in Infragistics, there is only "ID" field and no "name" field, inputname does not work.
@Html.Infragistics.DatePicker().InputName("datepicker1").ID("datepicker1") etc...
Can you tell me, how it is possible to transfer the datepicker value from the view to the controller ?
Thanks in advance !!!
Hi Tobias,
The initializers of DatePicker without a parameter or with DatePickerModel parameter can not use default framework of Mvc related to persistance. The client value actually comes to server as HttpContext.Request.Form[id] or similar, but Mvc framework is not able to make use of that. If application needs to get value from client, then it should use Mvc standard initializers like DatePickerFor(expression) or DatePicker(string).
For example, if application model has fields like
public class MyModel{ public DateTime Date1 { get; set; } public DateTime Date2 { get; set; } public string DateString { get; set; }}
and its view creates editors like
<%: Html.Infragistics().DatePickerFor(m => m.Date1).Render() %><%: Html.Infragistics().DatePicker("Date2").Render() %><%: Html.Infragistics().DatePicker("DateString").Render() %><%: Html.Infragistics().DatePicker().ID("DateString2").Render() %>
then within a controller, an application may get client values as following
[HttpPost]public ActionResult MyAppAction(MyModel model, string returnUrl){ DateTime date1 = model.Date1; DateTime date2 = model.Date2; string dateString = model.DateString; string dateString2 = HttpContext.Request.Form["DateString2"]; ...}
Note: if string-field is used by application model for DatePicker, then client value will come as 7 date fields in format: yyyy-M-d h:m:s.f. For example: 2012-8-21 0:0:0.0. It means that application should do some efforts to extract date fields and make sense of them. So, it is prefferable to use model-field with type of DateTime.
thank you, could you please send me the sample code in one project,
my controller function does not get the model data ...
I learned how to build Mvc-VB project and its impressive syntax and attached for you a sample.Please extract attachment to any directory on your machine. To reduce size of file, I did not include reference to Infragistics.Web.Mvc.dll, so, you will need to adjust corresponding references (in vbproj and web.config files) to dll located on your machine.
All other resources are local (igEditor) or coming from web (jquery).
Please run project, enter dates and click submit. The codes which get value from client are located in AccountController.vb.
thank you very much for this sample.
it works fine.