Skip to content
Advertisement

How to print Model Value of ASP.NET MVC in alert?

I have a MVC Code which seperates DateTime into two input fields and a button which save changes

@model WorkOrderDetailsViewModel
<div class="col-sm-3">
    <span>Start Date:@Html.TextBoxFor(m => m.StartDateTime, new { @class = "form-control", id="StartDate", @placeholder = "MM/DD/YYYY" })</span>
</div>
<div class="col-sm-3">
    <span>Start Time:@Html.TextBoxFor(m => m.StartDateTime, new { @class = "form-control", id="StartTime", @placeholder = "MM/DD/YYYY" })</span>
</div>

<div class="row">
    <button id="changeDate" class="btn btn-sm btn-primary pull-right">Save Changes</button>
</div>

Now How can I combine those two dates and time and show them on alert on clicking on save changes using jquery. My jquery Code is :-

$("#StartDate").datetimepicker({
    format: "L",
    minDate: moment()
}).data("DateTimePicker").date(moment.unix(getUrlParameter("time")).utc());

$("#StartTime").datetimepicker({
    format: "hh:mm A"
}).data("DateTimePicker").date(moment.unix(getUrlParameter("time")).utc());


$("#changeDate").click(function () {
    alert(); // I nees to show the combined value of date and time
});


Advertisement

Answer

The following code will show the date and time in a alert box

$("#changeDate").click(function () {

    var startDate = $("#StartDate").val();
    var startTime = $("#StartTime").val();

    alert("Date and time: " + startDate + " - " + startTime )) {
}); 
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement