Getting 404 error in ASP.NET Core Web API. With ASP.NET I am using Angular 7 for front end. When I click on save button of a form, the form data reaches to post method in angular but after click on save it shows 404 error. For this form I created first model where I define its property for database then I created controller for that model and use that property that I declared in model.
Angular service ts file:
export class MurderService {
BaseUrl :string ='';
constructor( private http:HttpClient, private config:ConfigService) {
this.BaseUrl=config.getApiURI();
}
murderQuestionnaire(data: any){
var murderBody={
Dead: data.Dead,
Wounded: data.Wounded,
CriminalsInvolved: data.CriminalsInvolved,
CriminalAppearance: data.CriminalAppearance,
VehiclesUsed: data.VehiclesUsed,
WeaponsDescription :data.WeaponsDescription
};
return this.http.post(this.BaseUrl +'/Complians' , murderBody);//upto here data reaches
successfully
}
}
API controller for this service:
[Route("api/[controller]")]
[ApiController]
public class ComplainMurderController : ControllerBase
{
[HttpPost]
[Route("Complians")]
//api:/Complians
public void PostComplainMurder(Complians complian)
{
var complianMurder = new Complians()
{
Dead = complian.Dead,
Wounded = complian.Wounded,
CriminalsInvolved = complian.CriminalsInvolved,
CriminalAppearence = complian.CriminalAppearence,
VehiclesUsed = complian.VehiclesUsed,
WeaponsDescription = complian.WeaponsDescription
};
try
{
// var result = await complian.Add(complianMurder);
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.Add(complianMurder);
authenticationContext.SaveChanges();
}
catch(Exception ex)
{
throw ex;
}
}
}
}
Error
POST http://localhost:49601/api/Complians 404 (Not Found)
Compliansbut you are callingapi/Complians.