Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass three parameters to url address using ASP.NET Core Web API

For now I have a procedure I wish to call:

CALL Get_Discharge_Station('2022-02-02', 6, 11800);

I want to pass these three parameters – 2022-02-02,6,11800 to url address, when I enter different date,number and number of station to get different data.

For now my API controller look like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;

namespace WebAPI.Controllers
{
    [Route("api/hqdataahs")]
    [ApiController]
    public class HQ_data_AHSController : ControllerBase
    {
        private readonly IConfiguration _configuration;

        public HQ_data_AHSController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        [HttpGet]
        public JsonResult Get()
        {
            string query = @"CALL Get_Discharge_Station('2022-02-02', 6, 11800);";

            DataTable table = new DataTable();

            string sqlDataSource = _configuration.GetConnectionString("AppCon");

            MySqlDataReader myReader;

            using (MySqlConnection mycon = new MySqlConnection(sqlDataSource))
            {
                mycon.Open();

                using (MySqlCommand myCommand = new MySqlCommand(query, mycon))
                {
                    myReader = myCommand.ExecuteReader();
                    table.Load(myReader);

                    myReader.Close();
                    mycon.Close();
                }
            }

            return new JsonResult(table);
        }
    }
}

What can I change to pass there three parameters in url address when I access the controller?`

>Solution :

declare the args

    [HttpGet]
    public JsonResult Get(string dataStr, int noodle, int frumpy)
    {

now construct the call

  string query = $"CALL Get_Discharge_Station('{dateStr}', {noodle}, {fumpy});"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading