【发布时间】:2015-05-14 15:38:47
【问题描述】:
我是mvvm 的新手,谁能帮我根据所选日期显示详细信息。当我运行我的代码时,它显示 500 错误与 post 和 get 方法。
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");
});
}
}
}
【问题讨论】:
-
错误是什么?你知道错误是服务器端还是客户端?您是否在您选择的浏览器中使用开发工具对其进行了调试?你见过原始的 HTTP 请求和响应吗?发布您的所有代码并要求我们查找您的问题不太可能得到您希望的响应。
-
@Bill 发布 500 内部服务器错误
-
这意味着你的服务器抛出了一个未处理的异常。您需要从服务器获取更详细的错误日志记录,或者最好调试服务器并逐步查看错误发生的位置。
标签: c# angularjs mvvm typescript