I have an MVC application with a number of forms. When the form is submitted it passed the users gps coordinates to the server. I also want to pass the clients current datetime.
Does anyone have any ideas as to the best way to do this?
The forms are standard html forms and use a basic submit.
My form would look like the one below. So how would I best attach the javascript datetime value to the submit 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>
            }
                You can use JavaScript and the Date function which is rendered on the clients machine.
var d = new Date();
Then you could pass the variable d to the server when you submit the co-ordinates.
From your edit:
In your Checkin method in theHome controller, you could specify:
public ActionResult Checkin(string hckLat, string hckLong, string hckDate) 
{
    var theDate = hckDate;
}
To set the value of hckDate, you could do:
On the submit button click:
<input type="button" name="theSubmitButton" id="theSubmitButton" value="Button"   onClick="setDate();">
function setDate() {
   var e = document.getElementById('hckDate');
   e.value = new Date();
}
This would then be sent to the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With