none
One datepicker that updates all the DateTime-values at the same time MVC Core

    Pertanyaan

  • I have a JQuery-date-picker in a form that works alright for each item in a foreach-loop. But I would like to have only one datepicker at the end of the view that sets all the DateTime-values for all the items at the same time. How do I do that? With Ajax(?) - I am not so familiar with Ajax...
    (All the items are stored in a session now before they are sent to an order-table when the order is completed. I don't think that is important for the question).
    Here is the form-code:
                            <form asp-action="EditPickUpDate" method="post">
                            <input type="hidden" value="@item.CartItemID"    
                             name="CartItemID" />
                            <input type="hidden" value="@item.PickUpDate"  
                            name=" PickUpDate" />
                            <input type="hidden" value="@Model.ReturnUrl" />
                            <input type="date" id="pickUpDate" class="form-
                             control" />
                            <input type="submit" value="pickUpDate" />
                            </form>
    And here is the part in the controller:
     
                            [HttpPost]
                            [ValidateAntiForgeryToken]
                            public ActionResult EditPickUpDate([Bind
                            (include:"PickUpDate")] AddCartItemViewModel
                             model, DateTime pickUpDate, CartItem item)
                            {
                               if (ModelState.IsValid)
                                 {
                                   pickUpDate = model.PickUpDate;
                                   ShoppingCart cart = GetCart();
                                   cart.AddPickUpDate(pickUpDate, item);
                                   SaveCart(cart);
                                  }
                             return RedirectToAction("Index", new {       
                             model.ReturnUrl });
                             }
    Rabu, 28 Maret 2018 19.35

Semua Balasan

  • Hi Harry_Xenon,

    Thank you for posting here.

    According to your question is more related to MVC, you could post a new thread in MVC forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Disarankan sebagai Jawaban oleh Mubassir Hasan Rabu, 05 September 2018 15.03
    • Saran Jawaban dibatalkan oleh Mubassir Hasan Rabu, 05 September 2018 15.03
    • Disarankan sebagai Jawaban oleh Mubassir Hasan Rabu, 05 September 2018 15.03
    • Saran Jawaban dibatalkan oleh Mubassir Hasan Rabu, 05 September 2018 15.03
    Kamis, 29 Maret 2018 07.51
  • You can do that using jquery:

    Here is the sample code for changing all other input value using one single date time 

    HTML

    <form>
    <input type="text" name="valueDate" class="singleDate" /> <br/>
    <input type="text" name="valueDate" class="singleDate" /> <br/>
    <input type="text" name="valueDate" class="singleDate" /> <br/>
    <input type="text" name="valueDate" class="singleDate" /> <br/>
    
    <input type="text" id="dateMain" />
    </form>
    
    
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
    <script
      src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"
      integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk="
      crossorigin="anonymous"></script>
    
    <script>
     $("#dateMain").datepicker({
                    dateFormat: 'dd-mm-yy',
                    changeMonth: true,
                    changeYear: true,
                    showButtonPanel: false,
                    
                    onClose: function(selectedDate) {
                    console.log(selectedDate);
                       $(".singleDate").each(function() {
                          $(this).val(selectedDate);
                      });
                    }
    
                }).datepicker("setDate", new Date());
    </script

    you can receive all the list date in your controller like this 

    public IActionResult GetDates(List<DateTime> valueDate){
    //Do your staff
    }

    Hope this work!

    Fiddle Link

    http://jsfiddle.net/pc6qrf4m/19/
    • Diedit oleh Mubassir Hasan Rabu, 05 September 2018 15.42 fiddle link Added
    Rabu, 05 September 2018 15.36