OutPut:
{
"$id": "1",
"_MenuList": [
{
"$id": "2",
"parentId": 3,
"menuName": "Details"
},
{
"$id": "3",
"parentId": 1,
"menuName": "No of Details"
}
]
}
In output "$id" autogenerate how to remove this.
Format Code Controller :
[Route("MenuController/getMenuList/input")]
[HttpPost]
public ReportMenu getMenuList([FromBody]LoginModel input)
{
DataTable reportvalue = new DataTable();
try
{
using (SqlConnection dataConnection = ConnectionString.getConnection())
{
SqlCommand command = new SqlCommand("USP_ReportMenu", dataConnection);
command.Parameters.AddWithValue("@userName", input.userName);
command.Parameters.AddWithValue("@password", input.password);
command.CommandType = CommandType.StoredProcedure;
using (SqlDataAdapter reportAdapter = new SqlDataAdapter(command))
{
reportAdapter.Fill(reportvalue);
}
}
}
catch (SqlException ex)
{
}
return getJson(reportvalue);
}
public ReportMenu getJson(DataTable tb)
{
ReportMenu menu = new ReportMenu();
List<MenuModel> listMenu = new List<MenuModel>();
for (int i = 0; i < tb.Rows.Count; i++)
{
MenuModel obj=new MenuModel();
obj.parentId = Convert.ToInt16(tb.Rows[i]["parentId"].ToString());
obj.menuName = tb.Rows[i]["reportName"].ToString();
listMenu.Add(obj);
}
menu._MenuList = listMenu;
return menu;
}
I want To this Type of ouput:
{"_MenuList": [
{
"parentId": 3,
"menuName": "Details"
},
{
"parentId": 1,
"menuName": "No of Details"
}
]
}
Kindly help for us.. I am new in Web API.