Submit datetime client form, MVC application

I have an MVC application with several forms. When the form is submitted, it passes the coordinates of the gps users to the server. I also want to give clients the current time and time.

Does anyone have any ideas on the best way to do this?

Forms are standard html formats and use basic submit.

My form will look like below. So, what is the best way for me to bind a javascript date and time value to a send call?

            @using (Ajax.BeginForm("CheckIn", "Home", "Nothing", new AjaxOptions { }))
            {
                <fieldset>
                    <p>Move your Tile here to let those around you see it...</p>
                    <input type="hidden" name="lat" id="hckLat" value="" />
                    <input type="hidden" name="lon" id="hckLon" value="" />
                    <input type="hidden" name="date" id="hckDate" value="" />
                    <input type="submit" value="Check In!" />
                </fieldset>
            }
+5
source share
2 answers

You can use the function JavaScriptand Date, which is displayed on the client machine.

var d = new Date();

You can then pass the d variable to the server when sending the coordinates.

:

Checkin Home controller :

public ActionResult Checkin(string hckLat, string hckLong, string hckDate) 
{
    var theDate = hckDate;
}

hckDate, :

:

<input type="button" name="theSubmitButton" id="theSubmitButton" value="Button"   onClick="setDate();">

function setDate() {
   var e = document.getElementById('hckDate');

   e.value = new Date();
}

.

+5

javascript:

var currentDateTime = new Date() 

, , moment.js, mvc

+1

All Articles