This is a migrated thread and some comments may be shown as answers.

[Solved] Use lambda expression in DatePicker().Name()

17 Answers 205 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mousam
Top achievements
Rank 1
Mousam asked on 19 Mar 2010, 01:16 AM
Hi,

I am using LINQ to SQL EF and the controls on my form is identified by the model. For example, the DueDate property of the data model is displayed as a textbox on the form.

<label for="BidDueDate">Bid Due Date:</label> 
<%= Html.TextBoxFor(model => model.Project.BidDueDate, String.Format("{0:g}", Model.Project.BidDueDate))%> 
<%= Html.ValidationMessageFor(model => model.Project.BidDueDate, "*")%> 

Instead of textbox I would like to use DatePicker control but I cannot use the model object to set the Name of the DatePicker. The error message appears saying "Cannot covert lamda expression to type string". Any ideas how to get it working.

I do not want to use hardcoded name for the DatePicker control.

<label for="BidDueDate">Bid Due Date:</label> 
<%= Html.Telerik().DatePicker() 
                    .Name(model => model.Project.BidDueDate) 
                    .Value(Model.Project.BidDueDate) 
%> 
<%= Html.ValidationMessageFor(model => model.Project.BidDueDate, "*")%> 

Thanks
Mousam

17 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 19 Mar 2010, 03:40 PM
Hello Mousam,

I am glad to inform you that requested feature is implemented.

For your convenience, I have attached the latest internal builds.

Kind regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mousam
Top achievements
Rank 1
answered on 23 Mar 2010, 01:29 AM
Thanks Georgi.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 05 May 2010, 07:47 AM
Using the latest nightly build I still am unable to use the model and get the same error. It seems the zip file with the updated build still does not have the assembly with the updated datepicker. Where can I get that updated build?
0
Georgi Krustev
Telerik team
answered on 05 May 2010, 08:14 AM
Hi Ed Buchsbaum,

The requested feature was introduced in the official service pack (Telerik_Extensions_for_ASPNET_MVC_2010_1_416) from the middle of April. What is the version of your assembly.
Note that this functionality is supported only with ASP.NET MVC 2.0 framework.

Regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 05 May 2010, 06:06 PM
The version of my assembly is 210.1.319.235.

How do I download the official service pack you refer to below? I don't see it in the downloads?

The requested feature was introduced in the official service pack (Telerik_Extensions_for_ASPNET_MVC_2010_1_416) from the middle of April. What is the version of your assembly.
Note that this functionality is supported only with ASP.NET MVC 2.0 framework.

Note, I am using MVC 2.0 with VS 2010.

Many Thanks,

Ed
0
Atanas Korchev
Telerik team
answered on 06 May 2010, 07:30 AM
Hi Ed Buchsbaum,

Service pack releases are available only to customers having a commercial license of Telerik Extensions for ASP.NET MVC. Often however we release hotfix build as forum attachments. You can download an up-to-date build from this forum thread.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 06 May 2010, 07:40 PM
Service packs are only available to licensed users makes no sense for a free open source product. I'm very disappointed in Telerik.

Plus the link you gave me returns this which is not very helpful!

Server Error

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.


0
Atanas Korchev
Telerik team
answered on 07 May 2010, 07:11 AM
Hi Ed Buchsbaum,

This is actually highlighted in our licensing FAQ section. However as I stated earlier should a critical bug be fixed we will attach hotfix builds in the forum.

The correct link is this.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 07 May 2010, 08:23 AM
Thanks. I was able to download the hotfix build. However I'm not getting all kinds of file not found errors. Is there a new documentation file to go with this new assembly. It seems there are breaking changes and without the documentation I have not idea how to fix them.

Many Thanks,
Ed
0
Atanas Korchev
Telerik team
answered on 07 May 2010, 08:43 AM
Hello Ed Buchsbaum,

You have probably not upgraded all files. Apart from the dll you need to copy the Scripts and Content folder.

The breaking changes are outlined in the online documentation:
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-changes-and-backward-compatibility.html
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-treeview-changes-and-backward-compatibility.html

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 07 May 2010, 07:59 PM
Hi,

Thank you. I have the new assembly and all supporting files installed. However I still get the same error with assembly version 2010.1.416.235

Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type

Source Error:

Line 4:  </div>
Line 5:  <div class="editor-field">
Line 6:      <%: Html.Telerik().DatePicker().Name(model => model) %>
Line 7:      <%: Html.ValidationMessageFor(model => model) %>
Line 8:  </div>

Any suggestions to getting around this error. I'm trying to use the datepicker inside a template so need the strongly typed model param.

Many Thanks,

Ed
0
Atanas Korchev
Telerik team
answered on 10 May 2010, 08:13 AM
Hi Ed Buchsbaum,

That's because you are not using the right syntax which is:

<%= Html.Telerik().DatePickerFor(model => model) %>

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 10 May 2010, 08:18 PM
Thank  you for your assistance.

Here is the issue I am having. If I use the DatePicker by itself inside a view like this it works fine:

 <div class="editor-label">
            <%: Html.LabelFor(model => model.DealDate) %>
        </div>
        <div class="editor-field">
            <%= Html.Telerik().DatePickerFor(model => model.DealDate) %>
            <%: Html.ValidationMessageFor(model => model.DealDate) %>
        </div>

However if I create a template for type DateTime and call it I get the following error:

Bound columns require a field or property access expression.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Bound columns require a field or property access expression.

Source Error:

Line 4:  </div>
Line 5:  <div class="editor-field">
Line 6:      <%= Html.Telerik().DatePickerFor(model => model) %>
Line 7:      <%: Html.ValidationMessageFor(model => model) %>
Line 8:  </div>

Here is how my template is coded:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %>
<div class="editor-label">
    <%: Html.LabelFor(model => model) %>
</div>
<div class="editor-field">
    <%= Html.Telerik().DatePickerFor(model => model) %>
    <%: Html.ValidationMessageFor(model => model) %>
</div>

Then I call it in the view like this:

   <%= Html.EditorFor(model => model.DealDate) %>

and I get this error:

Bound columns require a field or property access expression.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Bound columns require a field or property access expression.

Source Error:

Line 4:  </div>
Line 5:  <div class="editor-field">
Line 6:      <%= Html.Telerik().DatePickerFor(model => model) %>
Line 7:      <%: Html.ValidationMessageFor(model => model) %>
Line 8:  </div>




I'm confused as to why it works fine when called directly in a view, but I am unable to get it to work inside the template. My goal is to have the datepicker always be used for DateTime data type hence the template design.

Many Thanks,

Ed











0
Atanas Korchev
Telerik team
answered on 11 May 2010, 10:51 AM
Hi Ed Buchsbaum,

It seems there is a bug with
DatePickerFor(model => model)

Find attached a hotfix build which should address this problem.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 11 May 2010, 08:32 PM
Thanks Atanas , works great now! :)
0
Ed Buchsbaum
Top achievements
Rank 1
answered on 11 May 2010, 10:55 PM
Hi Atanas,

Thank you for the hotfix. It did fix the issue. However another issue remains and it is with validation. In my model I have a Deal class. The Deal class has the DealDate field and it is decorated with the Required attribute:

   [Required]
   public System.DateTime DealDate { get; set; }

I have a create form which uses the Create action method of the controller. Below is a partial code snippet form the Create action method on the controller.

  public ActionResult Create(Deal deal)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (GroupBuyDataContext db = new GroupBuyDataContext())
                    {
                        db.Deal.InsertOnSubmit(deal);
                        db.SubmitChanges();
                        return RedirectToAction("Index");
                    }
                }
                else
                {
                    // display the form with the errors from ModelState.Errors dicitonary
                     return View(deal);
                }

Here is the template for the type DateTime:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<div class="editor-label">
    <%= Html.LabelFor(model => model) %>
</div>
<div class="editor-field">
    <%= Html.TextBoxFor(model => model) %>
    <%= Html.ValidationMessageFor(model => model) %>
</div>

The DealDate is a required field and when the form is posted, the default model binder will add the ModelState error for DealDate. I have verified this with the debugger so that part is working fine.  (See attached file for debugger output)

In my view, if I use the template like this:

   <%= Html.EditorFor(model => model.DealDate) %>

Instead of seeing the form with the indicated errors, I am getting this yellow page:

The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.

Source Error:

Line 33:             <%: Html.ValidationMessageFor(model => model.DealPrice) %>
Line 34:         </div>
Line 35:         <%= Html.EditorFor(model => model.DealDate) %>
Line 36:         <%= Html.EditorFor(model => model.DealExpireDate) %>
Line 37:         <div class="editor-label">

However, if I simply call the DatePicker directly in the view like this:

        <div class="editor-label">
            <%: Html.LabelFor(model => model.DealDate) %>
        </div>
        <div class="editor-field">
            <%= Html.Telerik().DatePickerFor(model => model.DealDate) %>
            <%: Html.ValidationMessageFor(model => model.DealDate) %>
        </div>

The form returns with the error properly indicated

The DealDate field is required.

Is this a bug with the DatePickerFor extension method or am I missing something? And if so, is there another hotfix?

Many Thanks,

Ed
















0
Atanas Korchev
Telerik team
answered on 12 May 2010, 08:35 AM
Hi Ed Buchsbaum,

I am sending you a sample project showing how to work with validation. Check /Views/Shared/EditorTemplates/Date.ascx.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Date/Time Pickers
Asked by
Mousam
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Mousam
Top achievements
Rank 1
Ed Buchsbaum
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or