How to call Http.GetStringAsync with parameter?

  • Thread starter Thread starter Eskilote
  • Start date Start date
E

Eskilote

Guest
Hello!


So, I'm trying out Blazor and can't figure out how to post a parameter. I'm new to C# so the question is probably not Blazor-unique. See code below:

Calling code in razor page:

string strPropString;
protected override async Task OnInitAsync()
{
strPropString = await Http.GetStringAsync("api/Data/lookupId/");
}

the response is generated from the below code:

[HttpGet("[action]")]
public string lookupId()
{
string connectionString = "connstring;";
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand myCmd = new SqlCommand("sp_select_returnPropBetFromId", con))
{
myCmd.CommandType = CommandType.StoredProcedure;
myCmd.Parameters.Add(new SqlParameter("@propId", 1));
using (SqlDataReader reader = myCmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
return reader.GetValue(0).ToString();
}
}
}
}
}
}

Above line in bold just uses the static sql parameter of "1". How can I pass a parameter from the code that makes the http call?

Cheers!


/Eskil

Continue reading...
 
Back
Top