Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7912149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:31:19+00:00 2026-06-03T13:31:19+00:00

Not actually sure how to phrase my question. I’m using jqgrid in most of

  • 0

Not actually sure how to phrase my question.

I’m using jqgrid in most of my screens (not sure if its relevant info in this case),
Iv’e got two datetime pickers on the add/edit modal. I’ve been using this Date Time picker component, which worked well except i find that people aren’t fans of using sliders to capture time, esp if its something that needs to get entered frequently.

Along came the will_pickdate component which although its super luminous :P, seemed to answer my end users prayers, (my other option was to try and write my own component but i’ll give it a skip for now)

My problem comes in when i try and save. the will_pickdate component seems to be submitting its date time values as text, or its not mapping correctly when i call the TryUpdateModel method.

Client Side Code

      function CreateDateTimePicker(elem, ShowOn, OnClose) {

        setTimeout(function () {
    //code that works
            $(elem).datetimepicker({
                dateFormat: 'yy/mm/dd',
                timeFormat: 'hh:mm',
                showOn: ShowOn,
                buttonImageOnly: true,
                buttonImage: "/Images/date_time.jpg",
                changeYear: true,
                changeMonth: true,
                showButtonPanel: true,
                showWeek: true,
                onClose: function (dateText, inst) {
                    if (OnClose != null)
                        OnClose(dateText, inst);

                    $(this).focus();
                }
            }).attr('size', '16').next('img.ui-datepicker-trigger')
            .attr("tabIndex", "-1").css({ 'cursor': 'pointer', 'vertical-align': 'middle', 'padding-left': '3px', 'padding-bottom': '4px' });

//new code that sort of works.. eg component renders fine, but fails server side
            //$(elem).will_pickdate({
            //    timePicker: true,
            //    format: 'Y/m/d H:i',
            //    inputOutputFormat: 'Y/m/d H:i',
            //    militaryTime: true,
            //    allowEmpty: true,
            //    startView:'day',
            //    onSelect: function (date) {

            //        if (OnClose != null)
            //            OnClose();

            //        $(this).focus();


            //      //  $('#' + display[0].id).val(new Date($(elem).val()));
            //   //     $('#' + display[0].id+ '_display').val(new Date($(elem).val()));
            //       // alert($('#' + display[0].id).val());
            //    }
            //});

        }, 100);}

My add method.

  public ActionResult Edit(Down_Time_Capture viewModel, FormCollection formCollection)
    {
        Down_Time_CaptureRepository repository = new Down_Time_CaptureRepository();

        try
        {
            if (!ModelState.IsValid)
                return ReturnValidationFailure(ViewData.ModelState.Values);

            int item_id = Convert.ToInt32(formCollection["id"]);

            var model = repository.Where(o => o.DTCP_ID == item_id).SingleOrDefault();

            if (model == null)
            {
                //append any error code to allow jqgrid modal to handle error display
                Response.StatusCode = 400;
                return Json("Record not found.", JsonRequestBehavior.AllowGet);
            }               

    ====>   //code fails here, model tries to get updated but dies
            if (TryUpdateModel(model, formCollection.ToValueProvider()))
            {
                repository.Edit(model, User.Identity.Name);
                repository.Save();
                return Json("Updated successfully.", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return ReturnValidationFailure(ViewData.ModelState.Values);
            }
        }
        catch (Exception ex)
        {
           ...
        }

    }

What Iv’e noticed is that the view model is valid and contains the values in datetime format, but when i try update my model from the db, it fails with the following message.

*The parameter conversion from type ‘System.String’ to type ‘..Portal.Models.Down_Time_Capture’ failed because no type converter can convert between these types.*

I’ve tried converting the value to a date format in my javascript/jquery, and append it to my Date Input field… but it still submits it as string

I’ll provide any other information if its needed, but this is a strange one :/

UPDATE:

My view only contains the html for the jqgrid component. I’ve added a jsfiddle link below.

Link To JsFiddle – Includes code for both datepickers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:31:21+00:00Added an answer on June 3, 2026 at 1:31 pm

    Normally, when using a view model approach, you use a mapper (such as Automapper) to move the captured values from the view model to the persisted object. What you are doing is having MVC bind the captured values to the view model, then you’re basically throwing out the Down_Time_Capture instance and binding all over again from the form to whatever the type is returned by Down_Time_CaptureRepository (it’s not Down_Time_Capture, is it? in that case, you’re doing double the work).

    First let’s try and clean up your action a bit:

      public ActionResult Edit(int id)
        {
            Down_Time_CaptureRepository repository = new Down_Time_CaptureRepository();
    
            var model = repository.Where(o => i.DTCP_ID == id).SingleOrDefault();
    
            if (model == null)
                {
                    //append any error code to allow jqgrid modal to handle error display
                    Response.StatusCode = 400;
                    return Json("Record not found.", JsonRequestBehavior.AllowGet);
                }  
    
    
                if (TryUpdateModel(model))
                {
                    repository.Edit(model, User.Identity.Name);
                    repository.Save();
                    return Json("Updated successfully.", JsonRequestBehavior.AllowGet);
                }
    
                return ReturnValidationFailure(ViewData.ModelState.Values);
        }
    

    This will_pickdate component does seem to send the DateTime value across validly (the value will come over the wire as a string, and then MVC’s binder will convert the value to a DateTime when the form field’s name matches the property name of the model being bound).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure how to phrase my question properly but I want to
I'm not exactly sure how to phrase this, but here goes... We have a
I'm not actually sure what they are asking me to do. This is the
Not quite sure how to phrase this, but will do my best. I have
I'm not actually sure how to ask the question so here's what I'm doing:
I'm not sure exactly how to phrase this, but here goes: I have a
Sorry for the vague title but I'm not quite sure how to phrase this.
I'm actually not sure if this is exactly a left join; I'm not an
I have an interesting question, but I'm not sure exactly how to phrase it...
Actually I was not sure so, I followed git amend approach everytime. Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.