0

ASP.NET MVC 6(DNX 4.5.1).

In my PUT method.

public class MyController : ApiController
{
    .......
// UPDATE
    [Microsoft.AspNet.Mvc.HttpPut]
    public void Update()
    {
        try
        {
            var item = new Item()
            {
                UserName = Request.Form["UserName"]
            };
            _itemRespository.Update(item);
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.Message);
        }
    }

What I got:

Error CS1061 'HttpRequestMessage' does not contain a definition for 'Form' and no extension method 'Form' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?) MyProject.DNX 4.5.1

There is a similar question, but I don't see help me.

EDIT:

The link uses POST to pass the data to the method. He passed string value in the method. In another word, he knows the value in advance. Well, in my case I use jqgrid to edit my data. After I click the submit button, I think that the edited data is from the Request Form. I don't know it yet in advance.

11
  • The answer you are linking to is pretty self explanatory. What do you not understand or still have questions on?
    – Igor
    Jan 21, 2016 at 21:01
  • That is for POST, mine is PUT. So how can I borrow the code? IF So, please paste your code.
    – user1108948
    Jan 21, 2016 at 21:02
  • It is the exact same answer whether its POST, PUT, or DELETE. You should pass the data directly using method parameters and an attribute to specify whether its coming from the body or from the uri. The only exception is GET where its then only possible to include data in the URL or in the HTTP header as you cannot pass anything in the payload (ie data) of the request.
    – Igor
    Jan 21, 2016 at 21:05
  • The example passed a string, however in my example I have to pass an object.(POCO). Not sure how?
    – user1108948
    Jan 21, 2016 at 21:08
  • The exact same way as a string. See this article/how to on working with web apis: weblog.west-wind.com/posts/2012/May/08/…
    – Igor
    Jan 21, 2016 at 21:09

2 Answers 2

0

Here are 2 good starting points for how to pass dynamic form content to a web api method.

Sending HTML Form Data in ASP.NET Web API: Form-urlencoded Data

Stackoverflow question - How to get POST data in WebAPI?

So your question should be rephrased as how do you work with dynamic form content and the Web API framework. It has nothing to do with what web method (POST, PUT, DELETE, GET) you are using.

3
  • Please post your code for my specific case. It is not an answer. It just a comment.
    – user1108948
    Jan 21, 2016 at 21:58
  • @Love You do not really need an answer, you need a book or some other type of learning/introduction material. At the moment you are looking for quick answers without understanding why something works the way it does. Sometimes this is ok but not when you fail to understand the fundamental concepts of the platform you are developing on/for. Without this core knowledge you will continue to struggle at every turn. I gleaned this based on some of your other questions. I highly recommend you take a couple of hours and read up on Web Api before continuing any further. I wish you the best.
    – Igor
    Jan 21, 2016 at 22:32
  • The difficult thing is that the html structure is simple when using jqgrid. <body> <table id="jqGrid"></table> <div id="jqGridPager"></div></body>. That's it. We don't know selectors in the form. All the forms structure are hidden in the jqgrid. See the jqgrid demo.
    – user1108948
    Jan 22, 2016 at 1:08
-1
Microsoft.AspNet.Mvc.HttpPut

ASP.NET MVC 6(DNX) doesn't support to get it. Unless we use

System.Web.Http.HttpPut

Your Answer

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