Last post May 02, 2020 01:04 AM by mgebhard
Member
39 Points
362 Posts
May 01, 2020 10:42 PM|ahmedbarbary|LINK
I work on asp.net core 2.2 really when assign value to id on url as id=5
it display on debugging id=0 although i write value beside id
i write my URL as below
[HttpGet] [Route("GetAllFilters/{id}")] public IActionResult GetAllFilters(int id) { try { //string[] s = id.Split('='); // int Reportid = Convert.ToInt32(s[1]); var getfilters = _reportservice.GetReportFilter(id); return Ok(getfilters); } catch (Exception ex) { return NotFound(ex.Message); } }
I write on my URL as below
http://localhost:61265/api/GetAllFilters/report/id=5
so why id=0 this is my question and how to solve that
i send get request from google chrome browser visual studio 2017
160 Points
96 Posts
May 02, 2020 12:47 AM|timur.kh|LINK
Looking at your route template, you probably want to call your controller like so: http://localhost:61265/api/GetAllFilters/5
http://localhost:61265/api/GetAllFilters/5
All-Star
53081 Points
23648 Posts
May 02, 2020 01:04 AM|mgebhard|LINK
ahmedbarbary I write on my URL as below http://localhost:61265/api/GetAllFilters/report/id=5 so why id=0 this is my question and how to solve that
Proper URL syntax is...
Querystring
http://localhost:61265/api/GetAllFilters?id=5
Or route parameter which matches your route attribute.
I think you'll be interested in learning routing to controllers basics in ASP.NET Core
https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-3.1
And HTTP fundamentals.
https://launchschool.com/books/http/read/what_is_a_url
Member
39 Points
362 Posts
why id=0 when make it integer but if string it get value ?
May 01, 2020 10:42 PM|ahmedbarbary|LINK
I work on asp.net core 2.2 really when assign value to id on url as id=5
it display on debugging id=0 although i write value beside id
i write my URL as below
I write on my URL as below
http://localhost:61265/api/GetAllFilters/report/id=5
so why id=0 this is my question and how to solve that
i send get request from google chrome browser visual studio 2017
Member
160 Points
96 Posts
Re: why id=0 when make it integer but if string it get value ?
May 02, 2020 12:47 AM|timur.kh|LINK
Looking at your route template, you probably want to call your controller like so:
http://localhost:61265/api/GetAllFilters/5
All-Star
53081 Points
23648 Posts
Re: why id=0 when make it integer but if string it get value ?
May 02, 2020 01:04 AM|mgebhard|LINK
Proper URL syntax is...
Querystring
http://localhost:61265/api/GetAllFilters?id=5
Or route parameter which matches your route attribute.
http://localhost:61265/api/GetAllFilters/5
I think you'll be interested in learning routing to controllers basics in ASP.NET Core
https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-3.1
And HTTP fundamentals.
https://launchschool.com/books/http/read/what_is_a_url