İçeriğe geç

The requested resource does not support http method ‘POST’

Create Model

    public class LoginViewModel
    {
        public string UserName { get; set; }
        public string Password { get; set; }
    }

Update the controller

    [RoutePrefix("api/Membership")]
    public class MembershipController : ApiController
    {
        // GET: /api/Membership/validate?UserName=hello&Password=World
        [HttpGet]
        [Route("validate")]
        public IHttpActionResult ValidateUser(string UserName, string Password)
        {
            return Ok(UserName);
        }

        // POST: api/Membership/validate
        [HttpPost]
        [Route("validate")]
        public IHttpActionResult ValidateUserP(LoginViewModel vm)
        {
            return Ok(vm);
        }

    }

The Html form should be find here is mine just in case.

<div>
    <form id="form2" action="http://localhost:52803/api/Membership/validate" method="post">
        <div>
            <input name="UserName" value="Hello" />UserName<br />
            <input name="Password" value="World" />Password<br />
            <input type="submit" value="Submit" /><br />
        </div>
    </form>
</div>

Alıntıdır Apr 11, 2018 08:48 PM|LINK

Kategori:C#

Bu yazı yorumlara kapalı.