Reputation: 39
How can I pass string parameter in Web API
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:60698/api/values/GetBynamed/sudeesh3'.","MessageDetail":"No action was found on the controller 'Values' that matches the request."}
public IHttpActionResult getbynamed(string name)
{
List<ImgModel> list1 = new List<ImgModel>();
ImgModel mod = new ImgModel();
SqlConnection con = new SqlConnection(cs);
if (con.State == ConnectionState.Closed) con.Open();
SqlCommand cmd = new SqlCommand("select * from tbl_details where name='" + name + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
mod.id = Convert.ToInt32(dr[0].ToString());
mod.img = dr[1].ToString();
mod.name = dr[2].ToString();
mod.phone = dr[3].ToString();
list1.Add(mod);
}
return Ok(list1);
}
else
{
return NotFound();
}
}
Upvotes: 1
Views: 9869
Reputation: 1350
use this one:
[Route("api/values/getbynamed/{name}"]
public IHttpActionResult getbynamed(string name)
{
//Do something
}
Upvotes: 1
Reputation: 18973
You need add route configure for API
[Route("api/values/getbynamed/{name}")]
public IHttpActionResult getbynamed(string name)
{
}
Upvotes: 1