Every time I execute my program, it consistently displays a 500 error message when using both the POST and GET

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");
            });
        }
    }
}

Answer №1

Make sure to include the dateTime in your request.

public GetData(dt: Date): void {
                this.$http.get("/Schedule/GetData").suc

Your controller may be returning a 500 because of this missing dateTime parameter. Try updating your code like this:

public GetData(dt: Date): void {
                    this.$http.get("/Schedule/GetData?dt=" + dt.toString()).suc

Remember to format your datetime correctly for both C# and JavaScript to understand.

Answer №2

Thank you to everyone for the help. I have resolved the issue and here is the updated code...

    public GetDetails(date: string): void {
        this.$http.get("/Schedule/GetData", { params: { date: date } }).success((response: any, statusCode: any) => {
            this.tripDetails = response;
            console.log(response);
        }).error((response: any, statusCode: any) => {
            console.log(response);
        });
    }

    public GetData(date: string): void {
        this.$http.get("/Schedule/GetData", { params: {} }).success((response: any, statusCode: any) => {
            this.tripDetails = response;
            this.isLoading = false;
            console.log(response);
        }).error((response: any, statusCode: any) => {
                alert("An error occurred");
        });
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Are there any methods to utilize Zod for validating that a number contains a maximum of two decimal places?

How can I ensure that a numeric property in my object has only up to 2 decimal digits? For example: 1 // acceptable 1.1 // acceptable 1.11 // acceptable 1.111 // not acceptable Is there a method to achieve this? I checked Zod's documentation and sea ...

Binding a value from a template model to the parent scope in AngularJS using directives

I have been attempting to develop an angular directive that mimics the functionality of this jquery jsfiddle. http://jsfiddle.net/RCaCM/7/ The main goal of the directive is for the controller scope to contain a width value, which will be displayed in the ...

A guide to finding the mean in Angular by utilizing JSON information

import { Component, OnInit } from "@angular/core"; import { MarkService } from "../app/services/marks.service"; @Component({ selector: "app-root", templateUrl: "./app.component.html", styleUrls: ["./app.component.scss"] }) export class AppComp ...

Using ReactJS with Material UI and applying styles with withStyles including themes in TypeScript

I've been working on converting the Material UI Dashboard into TypeScript. You can find the original code here: Material UI Dashboard One issue I'm encountering is that I am unable to define CSS styles within the withStyles function while export ...

Angular ngFor not displaying the list

I'm encountering an issue with my HTML page where I'm using NGFor with an array. The error message I receive is as follows: landingpage.component.html:142 ERROR Error: Cannot find a differ supporting object '[object Object]' of type &ap ...

Activate the radio button upon page load in angularjs

<div class="form-group" style="margin-top: 20px;" ng-repeat="row in skuDetails"> <label class="checkbox-inline"> <input type="radio" name="amount_{{$index}}" value="amount" ng-model="row.amount" ng-checked="row.reductionAmount != &apos ...

Tips for sending code confirmation in Amazon Cognito identity using nest.js

Having some issues with implementing AWS Cognito login in Nest.js? Check out this helpful guide on token validation: https://medium.com/weekly-webtips/token-validation-with-aws-cognito-and-nestjs-6f9e4088393c. I need to add a feature where users receive ...

Retrieve a particular element from an array within a JSON object using Ionic

I am currently facing a challenge in extracting a specific array element from a JSON response that I have retrieved. While I can successfully fetch the entire feed, I am struggling to narrow it down to just one particular element. Here is what my service ...

Issue with Angular standalone component importation causing rendering issue in HTML

Recently, I started working with Angular and I am currently creating a clone using Firebase. While working on this project, Angular is throwing two errors at me: The Component AppComponent is standalone and cannot be declared in an NgModule. Should it b ...

Maintaining focus on UI grid cellTemplate editableCellTemplate is not a problem

Currently, I am utilizing angular-ui-grid and attempting to display a mix of various cell templates. Specifically, I want certain grid cells to change their class/color based on the entity's property. Additionally, some cells should display a button t ...

Creating a custom React hook in TypeScript to handle mouse events

I have been working on creating a custom hook in TypeScript/React, and I am looking to convert the code snippet below into a custom hook. Currently, I am passing handleClick to the onClick attribute in a div element to detect user clicks and route them to ...

The trouble with React Navigation encountered with TypeScript: This Entity Cannot Be Invoked

Currently, I'm facing a typescript issue after upgrading to React Navigation 5. The specific error message reads: There is an issue with calling this expression. The union type '{ <RouteName extends "Stack1Screen1" | "Home&quo ...

Expect a promise to be resolved in the RootCtrl of Angular using $http

One of the functions in my RootCtrl is responsible for calling an http api and returning the result. $scope.checkAccess = function(){ var result = MyService.me(); result.then(function(response){ console.log(response); if (response. ...

Array updating using the foreach method in Angular

Hey everyone, I've encountered an error that seems to be related to scope and I could use some advice. I'm currently looping through an array and trying to push the results to another array. However, when I attempt to push the results to public m ...

Tips on leveraging an attribute for type guarding in a TypeScript class with generics

Is there a way to utilize a generic class to determine the type of a conditional type? Here is a basic example and link to TS playground. How can I access this.b and this.a without relying on as or any manual adjustments? type X<T> = T extends true ...

Mastering the art of storing data in AngularJS services

When working with a table and adding items such as products and prices, I am looking to store this data in a service. Could you provide guidance on how to achieve this task effectively? routerApp.controller('products', function ($scope, myservic ...

Replicating an array of typed objects in Angular2

I have a collection of specific object types and I'm looking to duplicate it so that I can work on a separate version. In order for the configuratorProduct to function correctly, I need to provide it with a copy of the listProducts values: listPro ...

Leverage TypeScript to enforce the value of a property based on the keys of another property

The issue at hand is illustrated in the following example: type ExampleType = { properties: { [x: string]: number; }; defaultProperty: string; }; const invalidExample: ExampleType = { properties: { foo: 123, }, defaultProperty: "n ...

Enhancing Bootstrap UI Typeahead to Display Multiple Fields in Results List

Having encountered the same issue as described in this question: Bootstrap-UI Typeahead display more than one property in results list? I made adjustments to the Plunker provided in the answer to fit my requirements: http://plnkr.co/edit/FdkvCUUD3ob7dt2 ...

Tips for incorporating dynamic parameters/variables into templates displayed using ng-bind-html or a custom directive (within ng-repeat)

EDIT: I have created a solution sample based on the initial answer. However, I am open to further suggestions and would appreciate any help in filling the gaps in my knowledge (please refer to the comments). plnkr.co/edit/mqGCaBHptlbafR0Ue17j?p=preview OR ...