There is the following method on the server:
public ContentResult GetRequestsInPeriod(DateTime? startOf, DateTime stopOf) { var now = DateTime.Now; var _startOf = startOf?? new DateTime(now.Year, now.Month, 1); var _stopOf = stopOf?? now.AddDays(1); var requests = _requestService.GetRequestsInPeriod(_startOf, _stopOf) return Content(JsonConvert.SerializeObject(requests), "application/json") } There is the following view:
<div ng-app="app"> <div ng-controller="ReportController"> <div class="container"> <div class="panel panel-default"> <div class="panel-heading"> Параметры отчета: </div> <div class="panel-body"> <form class="form-inline"> <div class="form-group"> <h4>Период отчета:</h4> <label>С:</label> <div class="input-group col-md-4"> <input type="text" name="startOf" class="form-control" uib-datepicker-popup="dd.MM.yyyy" ng-model="startOf" is-open="popup1.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button> </span> </div> <label>По:</label> <div class="input-group col-md-4"> <input type="text" name="stopOf" class="form-control" uib-datepicker-popup="dd.MM.yyyy" ng-model="stopOf" is-open="popup2.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open2()"><i class="glyphicon glyphicon-calendar"></i></button> </span> </div> </div> </form> </div> <div class="panel-footer"> <input type="button" value="Получить отчет" ng-click="getReport(startOf, stopOf)" class="btn btn-default" /> </div> </div> </div> <h3 class="text-center">Простой оборудования по заявкам за период: с {{startOf}} по {{stopOf}}</h3> <h4>Отчет выполнил: @Model.ReportInfo.Author</h4> <h4>Дата/время получения отчета: @DateTime.Now.ToString("dd.MM.yyyy hh:mm")</h4> <!--Здесь таблица для отображения списка заявок--> </div> </div> js code:
var app = angular.module('app', ['ui.bootstrap', 'ngLocale']); app.controller('ReportController', ['$scope', '$http', function ($scope, $http) { var now = new Date(); $scope.startOf = new Date(now.getFullYear(), now.getMonth(), 1); $scope.stopOf = now.setDate(now.getDate() + 1); $scope.getReport = function (startOf, stopOf) { console.log(startOf); console.log(stopOf); var url = '/Report/GetRequestsInPeriod'; $http.get(url) .success(function (data) { $scope.list = { requests: data }; }); }; $http.get('/Report/GetRequestsInPeriod') .success(function (data) { $scope.list = { requests: data }; }); $scope.dateOptions = { startingDay: 1 }; $scope.open1 = function () { $scope.popup1.opened = true; }; $scope.open2 = function () { $scope.popup2.opened = true; }; $scope.popup1 = { opened: false }; $scope.popup2 = { opened: false }; }]); Help to implement the getReport method (startOf, stopOf) in the angularjs controller, to be more precise how to form the url that the entered values would be transferred to the server in the input field ( startOf , stopOf ).
urlthat is specified in thegetReport()method, then this is the problem, if the parameter were of typeintI would do so"/Report/Requests?parameterId="+id; but I don’t understand how to do it withDateTimeat the support, like this:"/Report/Requests?startOf=+startOf+"&stopOf="+stopOf;nullin the parameters comes to the server - Bald$httpsecond parameter is the config :) in which you can set the data field to be transmitted. - Grundy