1

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();
                }

            }

2 Answers 2

1

use this one:

[Route("api/values/getbynamed/{name}"]
public IHttpActionResult getbynamed(string name)
{
    //Do something
}
Sign up to request clarification or add additional context in comments.

Comments

1

You need add route configure for API

[Route("api/values/getbynamed/{name}")]
public IHttpActionResult getbynamed(string name)
{
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.