jquery - How to make use of an ASP.Net MVC controller action using Ajax to return the difference between two dates in a form? -
i'm using mvc3 , have view used book leave employees. part of want display number of days taken based on 2 dates enter - i've done in rudimentary way using jquery want make use of controller action i've got return single value based on 2 dates (it takes account weekends , bank holidays).
the question is, best way pass values of datefrom , dateto (the 2 inputs) controller , retrieve result using ajax? want value update whenever either of dates changed , without submitting whole form.
i'm not sure of best practice sort of thing appreciated.
the question is, best way pass values of datefrom , dateto (the 2 inputs) controller , retrieve result using ajax?
you subscribe change event of textboxes , send ajax request:
$(function() { $('#datefrom, #dateto').change(function() { // whenever user changes value send ajax request: $.ajax({ url: '@url.action("someaction", "somecontroller")', type: 'post', contenttype: 'application/json; charset=utf-8', data: json.stringify({ datefrom: $('#datefrom').val(), dateto: $('#dateto').val() }), success: function(result) { // todo: ajax call succeeded => results } }); }); }); and controller action this:
public actionresult someaction(datetime datefrom, datetime dateto) { ... }
Comments
Post a Comment