Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sndp 1 post 71 karma points
    Jun 27, 2016 @ 07:36
    Sndp
    0

    ASP.Net : The requested resource does not support http method 'GET'.

    I have hosted my .Net MVC application 4.5 and Asp.Net Web Api 2.0 in Godaddy server. When I try to post my data to database server through Web Api I got an error "The requested resource does not support http method 'GET'." Its work ok when I tried to post my data directly to database without going through Web Api.

    1) My MVC method.

    [HttpPost] public ActionResult Create(ItemRegisterViewModel model) { var returnObject = new ResponseObject(); returnObject.IsSuccess = true;

            if (model.ItemTypeId != 0)
            {
                if (ModelState.IsValid)
                {
                    var apiClient = new WebApiClient();
                    returnObject = apiClient.Post("api/Item/Create", model);
    
                    if (returnObject != null && returnObject.IsSuccess)
                    {
                        TempData["ItemSuccessCreate"] = returnObject.Message;
                        return RedirectToAction("Create");
    
                    }
                    TempData["ErrorMessage"] = returnObject.Message;
                    ModelState.AddModelError("", returnObject.Message);
                }
                else
                {
                    TempData["ErrorMessage"] = returnObject.Message;
                    ModelState.AddModelError("", "Required fields are required");
                }
            }
            else
            {
                ModelState.AddModelError("ItemTypeId", "Item Type is required. Select any item type above.");
            }
            model.ItemTypeList = inventoryController.GetItemTypes();
    
            return View("Create", model);
        }
    

    2) My API post method:

    [HttpPost] public HttpResponseMessage Create(ItemRegisterViewModel model) { HttpResponseMessage responseMessage = new HttpResponseMessage(); ResponseObject responseObject = new ResponseObject(); UnitOfWork unitOfWork = new UnitOfWork(_database); responseObject.IsSuccess = true; if (ModelState.IsValid) { try { List

            responseMessage = Request.CreateResponse(HttpStatusCode.OK, responseObject, "application/json");
            return responseMessage;
        }
    
  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 08, 2016 @ 10:50
    Warren Buckley
    0

    Hello Sndp,
    Is this more of a general error with Umbraco, than the Umbraco Forms addon product itself?

    But to answer your question as you are missing [HttpGet] attribute on the method then ASP.NET MVC will not allow you to do a HTTP Get of that resource, hence the error message it is returning.

    I hope that helps you.

    Thanks,
    Warren

Please Sign in or register to post replies

Write your reply to:

Draft