I'm seeking assistance with mvvm
as I am new to it. Can anyone help me in displaying details based on the selected date? Upon running my code, I encounter a 500
error with both the post
and get
methods.
Schedule.cshtml
<div class="col-lg-8" ng-app="ScheduleApp" ng-controller="ScheduleController" ng-cloak>
<table align="center">
<tr>
<td>Select Date</td>
<td>
<input type="date" class="form-control" id="dt" name="dt">
<input type="button" ng-click="vm.GetDetails(dt)" value="check" class="btn btn-default"/>
</td>
</tr>
</table>
<table align="center" border="1">
<tr>
<td><b>Trip ID</b></td>
<td><b>Booked By</b></td>
<td><b>Phone</b></td>
<td><b>Email</b></td>
<td><b>Car</b></td>
<td><b>Driver</b></td>
<td><b>Time</b></td>
</tr>
<tr ng-repeat="c in vm.books">
<td><p id="p1">{{c.TripId}}</p></td>
<td><p id="p2">{{c.BookedBy}}</p></td>
<td><p id="p3">{{c.Phone}}</p></td>
<td><p id="p4">{{c.Email}}</p></td>
<td><p id="p5">{{c.CarId}}</p></td>
<td><p id="p6">{{c.DriverId}}</p></td>
<td><p id="p7">{{c.StartTime}}</p></td>
</tr>
</table>
</div>
ScheduleController.cs
public JsonResult GetData(DateTime dt)
{
try
{
babyEntities1 ctx = new babyEntities1();
var bookings = from c in ctx.Trips
where c.Date == dt
select new
{
c.TripId,
c.BookingNo,
c.Date,
c.StartTime,
c.EndTime,
c.AccountId,
c.BookedBy,
c.PaxId,
c.PaxNo,
c.Phone,
c.SourceId,
c.SourceAddressId,
c.DestinationID,
c.DestAddressId,
c.Via,
c.Flight,
c.PaxComments,
c.TripEnd,
c.CarId,
c.DriverId,
c.PayId,
c.Amount,
c.Toll,
c.Parking,
c.FuelSur,
c.CardId,
c.AdminFee,
c.ExtraFee,
c.FeeComments,
c.UserId,
c.TotalAmount
};
return Json(bookings, JsonRequestBehavior.AllowGet);
}
catch
{
return Json(new { msg = "error" }, JsonRequestBehavior.AllowGet);
}
}
ScheduleController.ts
module Main.Schedule {
export interface IScheduleScope extends ng.IScope {
vm: ScheduleController;
}
export class ScheduleController {
public isBusy: boolean;
public books: Main.Book.Book;
//Default constructor
constructor(private $scope: IScheduleScope, private $http: ng.IHttpService) {
$scope.vm = this;
// this.books = new Main.Book.Book();
// var dt: Date;
// this.GetData(dt);
}
public GetDetails(dt: Date): void {
this.$http.post("/Schedule/GetData", { Obj: this.GetData }).success((data: any, status: any) => {
if (data.msg == 'success') {
this.GetData(dt);
alert("Saved");
}
else
alert('Error');
}).error((data: any, status: any) => {
alert("Error");
});
}
public GetData(dt: Date): void {
this.$http.get("/Schedule/GetData").success((data: any, status: any) => {
this.books = data;
this.isBusy = false;
console.log(data);
}).error((data: any, status: any) => {
alert("Error");
});
}
}
}