Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • I have an Html.BeginForm that has several controls such as Html.DropDownListFor and HtmlTextBoxFor to collect information for creating a new user.


                                    I want to use the DevEx DateEdit control instead of a simple TextBoxFor but how do I bind it to one of the strongly typed model properties? Nice would be a "DateEditFor" extension...Thx for some ideas!


                                    Here is an example of what I have.


                                    @model Public.Models.SiteMember

                                    @using (Html.BeginForm())

                                    {

                                    @Html.ValidationSummary()

                                    <p>Your first name: @Html.TextBoxFor(x => x.FirstName) </p>

                                    <p>Your last name: @Html.TextBoxFor(x => x.LastName) </p>


                                    @*<p>Your date of birth: @Html.TextBoxFor(x => x.DOB)</p>*@


                                    <p>Your date of birth: </p>

                                    @Html.DevExpress().DateEdit( <<<--- how do I bind the selected data to my model so it can be submitted???

                                    settings => {

                                    settings.Name = "dobEdit";

                                    settings.Properties.DisplayFormatString = "D";

                                    settings.Date = DateTime.Now;

                                    }).GetHtml()


                                    <p>Your Address: @Html.TextBoxFor(x => x.Address)</p>

                                    <p>Your City: @Html.TextBoxFor(x => x.City)</p>

                                    <p>Your State: @Html.TextBoxFor(x => x.State)</p>

                                    <p>Your Zip Code: @Html.TextBoxFor(x => x.Zipcode)</p>

                                    <input type="submit" value="Create Member" />

                                    }

                                • David Kolb 11.09.2012

                                  I found the data binding method so I changed ".GetHtml()" to ".Bind(Model, "DOB").GetHtml()" and now I get one way binding in that the supplied date is shown, but when posting back, I get all my model data except DOB which has the default 01/01/0100 date so apparently was not set even though the rest of the SiteMember model properties were set. Also, I can't get the date picker to show - all I see is a text box with the date in the model supplied to the view.

                                • David Kolb 11.09.2012

                                  Got the calendar to work. Found that the DevEx project update tool did not add any styles to the _Layout master view.

                                  So just need to figure out how to do two way binding where the DateEdit control will update the DOB property in the model object to send to the postback. All the other controls update the model Ok.

                                • David Kolb 11.10.2012

                                  Actually since strong typed, I changed to ".Bind(Model.DOB).GetHtml()" but am still getting only 1 way binding in that the initial date is set according to the model, but I do not get the date posted back. Everything else in the Html.Begin form posts back. Just not the date.

                                          <p>Your date of birth: </p>
                                          @Html.DevExpress().DateEdit(
                                              settings => {
                                              settings.Name = "DobEdit";
                                              settings.Date = Model.DOB; <- this works from model to view
                                              settings.Properties.UseMaskBehavior = true;
                                              settings.Properties.NullText = "MM/dd/yyyy";
                                              settings.Properties.EditFormat = EditFormat.Custom;
                                              settings.Properties.DisplayFormatString = "MM/dd/yyyy";
                                              settings.Properties.EditFormatString = "MM/dd/yyyy";
                                          }).Bind(Model.DOB).GetHtml() <- but view to model does not work on postback

                                • David Kolb 11.10.2012

                                  I read I was supposed to use the special DevEx binder so added the below to the controller postback action but unfortunatley it still did not help. DOB is still not coming back from the DateEdit control.

                                  public ActionResult Member([ModelBinder(typeof(DevExpressEditorsBinder))] SiteMember pNewMember) // use DevExpress model binding so can get the date!

                                You must  log in  or  register  to leave comments

                                2 Solutions

                                Creation Date Rating Importance Sort by
                                0

                                Ok the name of the DateEdit control had to be DOB!!! This was not clear in the doc. And seems redundant since sort of already bound in two other places (i.e. the Date property and the Bind argument. Anyway it's working now.

                                You must  log in  or  register  to leave comments
                                0

                                Hello David,

                                At present, our Editors do not provide the capability to use the EditorFor syntax.
                                Please refer to the Q341608 - Editors - Add a method that allows the use of lambda expressions to bind an editor report for more information.

                                When using Model binding, make sure that you set:
                                - The Editor's Name property equal to the corresponding Model field;
                                - Use the DevExpressEditorsBinder in the corresponding Controller Post Action.

                                [C#]
                                @Html.DevExpress().DateEdit(settings => { settings.Name = MODEL_PROPERTY_HERE; })Bind(Model.MODEL_PROPERTY_HERE).GetHtml()

                                Take a look at the online Data Editors - Model Validation demo to see this approach in action.

                                You must  log in  or  register  to leave comments

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners