Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Error Cannot send a content-body with this verb-type in asp.net

$
0
0

I am getting this error while sending a int? id to web api 

here is the code for mvc i tried a lot to change parameters to send but i did not get the solution please solve it for me

public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            // Create a request using a URL that can receive a post. 
            WebRequest request = WebRequest.Create("http://localhost:6760/api/values/Edit");
            // Set the Method property of the request to POST.
            request.Method = "GET";
            // Create POST data and convert it to a byte array.
            request.ContentType = "application/json";
            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string json = serializer.Serialize(id);
                streamWriter.Write(json);
                streamWriter.Flush();
            }
            var response = (HttpWebResponse)request.GetResponse();
            if (response == null)
            {
                return HttpNotFound();
            }
            response.Close();
            return RedirectToAction("QuestionDetail", "Testing");

        }

and here is the code for web api to get it

[HttpGet]
        [Route("api/values/Edit")]
        public AddQuestion Edit(int? id)
        {
            AddQuestion addquestion = new AddQuestion();
           addquestion = db.AddQuestions.Find(id);
            return addquestion;

        }

also changed the parameter to 

public AddQuestion Edit(AddQuestion adq) 

and this one as well

public AddQuestion Edit(JObject json)

and empty as well


Viewing all articles
Browse latest Browse all 4850


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>