ASP .net core HttpGet with parameter resulting Bad Request












0















So I have a service using Axios to call my C# API
since i wanto to select specific data, I use get method with parameter



here's my service



let response = await Axios.get('/api/get-report', {
params: filter
});


and here's my filter object in typescript



export interface FilterModel {
employeeId?: string;
Month?: Date;
from?: Date;
to?: Date;
}


model on server



public class AttendanceReportFilterModel
{
public string EmployeeId { set; get; }
public DateTime? Month { set; get; }
public DateTime? From { set; get; }
public DateTime? To { set; get; }
}


and finally, here's my C# API



[HttpGet("get-report")]
public async Task<IActionResult> GetReport(FilterModel filter)
{
var Detail = await Service.GetReport(filter);
if (Detail == null)
{
return StatusCode(500, "Not Found");
}

return Ok(Detail);
}


whenever I call my service, its always returning Bad Request
anybody know why? and how to fix this?










share|improve this question

























  • When you are making request you are adding some parameters. Can you please provide URL from network? It seems that you are sending invalid date.

    – Volodymyr Bilyachat
    Nov 21 '18 at 3:14











  • Show FilterModel as defined on server side. Also show the filter params sent from client. You most likely have the [ApiController] and the filter is defaulting to bad request because of a missing or malformed parameter value.

    – Nkosi
    Nov 21 '18 at 3:19













  • Does it get hit while you debug or it doesn't even find the Url ? Whereas am not sure how you pass a body for get ?

    – Rahul
    Nov 21 '18 at 3:20











  • @Nkosi you can see my model in my post aboce, i aleady updated it. also i already use [ApiController]

    – hphp
    Nov 21 '18 at 3:38
















0















So I have a service using Axios to call my C# API
since i wanto to select specific data, I use get method with parameter



here's my service



let response = await Axios.get('/api/get-report', {
params: filter
});


and here's my filter object in typescript



export interface FilterModel {
employeeId?: string;
Month?: Date;
from?: Date;
to?: Date;
}


model on server



public class AttendanceReportFilterModel
{
public string EmployeeId { set; get; }
public DateTime? Month { set; get; }
public DateTime? From { set; get; }
public DateTime? To { set; get; }
}


and finally, here's my C# API



[HttpGet("get-report")]
public async Task<IActionResult> GetReport(FilterModel filter)
{
var Detail = await Service.GetReport(filter);
if (Detail == null)
{
return StatusCode(500, "Not Found");
}

return Ok(Detail);
}


whenever I call my service, its always returning Bad Request
anybody know why? and how to fix this?










share|improve this question

























  • When you are making request you are adding some parameters. Can you please provide URL from network? It seems that you are sending invalid date.

    – Volodymyr Bilyachat
    Nov 21 '18 at 3:14











  • Show FilterModel as defined on server side. Also show the filter params sent from client. You most likely have the [ApiController] and the filter is defaulting to bad request because of a missing or malformed parameter value.

    – Nkosi
    Nov 21 '18 at 3:19













  • Does it get hit while you debug or it doesn't even find the Url ? Whereas am not sure how you pass a body for get ?

    – Rahul
    Nov 21 '18 at 3:20











  • @Nkosi you can see my model in my post aboce, i aleady updated it. also i already use [ApiController]

    – hphp
    Nov 21 '18 at 3:38














0












0








0


0






So I have a service using Axios to call my C# API
since i wanto to select specific data, I use get method with parameter



here's my service



let response = await Axios.get('/api/get-report', {
params: filter
});


and here's my filter object in typescript



export interface FilterModel {
employeeId?: string;
Month?: Date;
from?: Date;
to?: Date;
}


model on server



public class AttendanceReportFilterModel
{
public string EmployeeId { set; get; }
public DateTime? Month { set; get; }
public DateTime? From { set; get; }
public DateTime? To { set; get; }
}


and finally, here's my C# API



[HttpGet("get-report")]
public async Task<IActionResult> GetReport(FilterModel filter)
{
var Detail = await Service.GetReport(filter);
if (Detail == null)
{
return StatusCode(500, "Not Found");
}

return Ok(Detail);
}


whenever I call my service, its always returning Bad Request
anybody know why? and how to fix this?










share|improve this question
















So I have a service using Axios to call my C# API
since i wanto to select specific data, I use get method with parameter



here's my service



let response = await Axios.get('/api/get-report', {
params: filter
});


and here's my filter object in typescript



export interface FilterModel {
employeeId?: string;
Month?: Date;
from?: Date;
to?: Date;
}


model on server



public class AttendanceReportFilterModel
{
public string EmployeeId { set; get; }
public DateTime? Month { set; get; }
public DateTime? From { set; get; }
public DateTime? To { set; get; }
}


and finally, here's my C# API



[HttpGet("get-report")]
public async Task<IActionResult> GetReport(FilterModel filter)
{
var Detail = await Service.GetReport(filter);
if (Detail == null)
{
return StatusCode(500, "Not Found");
}

return Ok(Detail);
}


whenever I call my service, its always returning Bad Request
anybody know why? and how to fix this?







typescript api asp.net-web-api asp.net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 3:37







hphp

















asked Nov 21 '18 at 3:00









hphphphp

1001113




1001113













  • When you are making request you are adding some parameters. Can you please provide URL from network? It seems that you are sending invalid date.

    – Volodymyr Bilyachat
    Nov 21 '18 at 3:14











  • Show FilterModel as defined on server side. Also show the filter params sent from client. You most likely have the [ApiController] and the filter is defaulting to bad request because of a missing or malformed parameter value.

    – Nkosi
    Nov 21 '18 at 3:19













  • Does it get hit while you debug or it doesn't even find the Url ? Whereas am not sure how you pass a body for get ?

    – Rahul
    Nov 21 '18 at 3:20











  • @Nkosi you can see my model in my post aboce, i aleady updated it. also i already use [ApiController]

    – hphp
    Nov 21 '18 at 3:38



















  • When you are making request you are adding some parameters. Can you please provide URL from network? It seems that you are sending invalid date.

    – Volodymyr Bilyachat
    Nov 21 '18 at 3:14











  • Show FilterModel as defined on server side. Also show the filter params sent from client. You most likely have the [ApiController] and the filter is defaulting to bad request because of a missing or malformed parameter value.

    – Nkosi
    Nov 21 '18 at 3:19













  • Does it get hit while you debug or it doesn't even find the Url ? Whereas am not sure how you pass a body for get ?

    – Rahul
    Nov 21 '18 at 3:20











  • @Nkosi you can see my model in my post aboce, i aleady updated it. also i already use [ApiController]

    – hphp
    Nov 21 '18 at 3:38

















When you are making request you are adding some parameters. Can you please provide URL from network? It seems that you are sending invalid date.

– Volodymyr Bilyachat
Nov 21 '18 at 3:14





When you are making request you are adding some parameters. Can you please provide URL from network? It seems that you are sending invalid date.

– Volodymyr Bilyachat
Nov 21 '18 at 3:14













Show FilterModel as defined on server side. Also show the filter params sent from client. You most likely have the [ApiController] and the filter is defaulting to bad request because of a missing or malformed parameter value.

– Nkosi
Nov 21 '18 at 3:19







Show FilterModel as defined on server side. Also show the filter params sent from client. You most likely have the [ApiController] and the filter is defaulting to bad request because of a missing or malformed parameter value.

– Nkosi
Nov 21 '18 at 3:19















Does it get hit while you debug or it doesn't even find the Url ? Whereas am not sure how you pass a body for get ?

– Rahul
Nov 21 '18 at 3:20





Does it get hit while you debug or it doesn't even find the Url ? Whereas am not sure how you pass a body for get ?

– Rahul
Nov 21 '18 at 3:20













@Nkosi you can see my model in my post aboce, i aleady updated it. also i already use [ApiController]

– hphp
Nov 21 '18 at 3:38





@Nkosi you can see my model in my post aboce, i aleady updated it. also i already use [ApiController]

– hphp
Nov 21 '18 at 3:38












1 Answer
1






active

oldest

votes


















1














Try to add




[FromQuery]




public async Task<IActionResult> GetReport([FromQuery] FilterModel filter)


So since you are doing binding to object you need to say where to take them https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.1#customize-model-binding-behavior-with-attributes.



Or you can do it just with parameters



public async Task<IActionResult> GetReport(string EmployeeId, DateTime? Month = null, DateTime? FromMonth = null, DateTime? ToMonth = null)





share|improve this answer


























  • there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

    – hphp
    Nov 21 '18 at 4:10











  • @hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:13











  • well now it's getting error code 500

    – hphp
    Nov 21 '18 at 4:15











  • @hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:17






  • 1





    ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

    – hphp
    Nov 21 '18 at 4:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404685%2fasp-net-core-httpget-with-parameter-resulting-bad-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try to add




[FromQuery]




public async Task<IActionResult> GetReport([FromQuery] FilterModel filter)


So since you are doing binding to object you need to say where to take them https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.1#customize-model-binding-behavior-with-attributes.



Or you can do it just with parameters



public async Task<IActionResult> GetReport(string EmployeeId, DateTime? Month = null, DateTime? FromMonth = null, DateTime? ToMonth = null)





share|improve this answer


























  • there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

    – hphp
    Nov 21 '18 at 4:10











  • @hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:13











  • well now it's getting error code 500

    – hphp
    Nov 21 '18 at 4:15











  • @hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:17






  • 1





    ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

    – hphp
    Nov 21 '18 at 4:18
















1














Try to add




[FromQuery]




public async Task<IActionResult> GetReport([FromQuery] FilterModel filter)


So since you are doing binding to object you need to say where to take them https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.1#customize-model-binding-behavior-with-attributes.



Or you can do it just with parameters



public async Task<IActionResult> GetReport(string EmployeeId, DateTime? Month = null, DateTime? FromMonth = null, DateTime? ToMonth = null)





share|improve this answer


























  • there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

    – hphp
    Nov 21 '18 at 4:10











  • @hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:13











  • well now it's getting error code 500

    – hphp
    Nov 21 '18 at 4:15











  • @hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:17






  • 1





    ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

    – hphp
    Nov 21 '18 at 4:18














1












1








1







Try to add




[FromQuery]




public async Task<IActionResult> GetReport([FromQuery] FilterModel filter)


So since you are doing binding to object you need to say where to take them https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.1#customize-model-binding-behavior-with-attributes.



Or you can do it just with parameters



public async Task<IActionResult> GetReport(string EmployeeId, DateTime? Month = null, DateTime? FromMonth = null, DateTime? ToMonth = null)





share|improve this answer















Try to add




[FromQuery]




public async Task<IActionResult> GetReport([FromQuery] FilterModel filter)


So since you are doing binding to object you need to say where to take them https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.1#customize-model-binding-behavior-with-attributes.



Or you can do it just with parameters



public async Task<IActionResult> GetReport(string EmployeeId, DateTime? Month = null, DateTime? FromMonth = null, DateTime? ToMonth = null)






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 4:12

























answered Nov 21 '18 at 3:55









Volodymyr BilyachatVolodymyr Bilyachat

9,26822949




9,26822949













  • there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

    – hphp
    Nov 21 '18 at 4:10











  • @hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:13











  • well now it's getting error code 500

    – hphp
    Nov 21 '18 at 4:15











  • @hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:17






  • 1





    ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

    – hphp
    Nov 21 '18 at 4:18



















  • there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

    – hphp
    Nov 21 '18 at 4:10











  • @hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:13











  • well now it's getting error code 500

    – hphp
    Nov 21 '18 at 4:15











  • @hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

    – Volodymyr Bilyachat
    Nov 21 '18 at 4:17






  • 1





    ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

    – hphp
    Nov 21 '18 at 4:18

















there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

– hphp
Nov 21 '18 at 4:10





there is no FromUri only FromBody, Form, Header, Query, Route, Services which one i have to use?

– hphp
Nov 21 '18 at 4:10













@hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

– Volodymyr Bilyachat
Nov 21 '18 at 4:13





@hphp updated my answer. I did posted for old aspnet. In core there is fromQuery

– Volodymyr Bilyachat
Nov 21 '18 at 4:13













well now it's getting error code 500

– hphp
Nov 21 '18 at 4:15





well now it's getting error code 500

– hphp
Nov 21 '18 at 4:15













@hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

– Volodymyr Bilyachat
Nov 21 '18 at 4:17





@hphp well at least its not bad request :) Seems to be that endpoint is hit but error in your code

– Volodymyr Bilyachat
Nov 21 '18 at 4:17




1




1





ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

– hphp
Nov 21 '18 at 4:18





ah yeah.. it's hit.. thanks... now i just have to debug my code logic thanks

– hphp
Nov 21 '18 at 4:18




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404685%2fasp-net-core-httpget-with-parameter-resulting-bad-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?