[英]Put request is not working using postman to web api 2 c#
I have a method in Api as follows我在 Api 中有一个方法如下
[HttpPut]
[Route("UpdateTeacher")]
public IHttpActionResult UpdateTeacher(BusinessLayerTeacher Obj)
{
try
{
BusinessLayerTeacher obj = new BusinessLayerTeacher ();
string status = BusinessLayerObject.UpdateTeacher(TeacherObj);
return Ok(status);
}
catch
{
return NotFound();
}
}
Now in post man i am sending the put request to update the teacher object.现在在邮递员中,我正在发送 put 请求以更新教师对象。 It is not triggering this updateTeacher() method.
它不会触发此 updateTeacher() 方法。
You are instantiating a new BusinessLayerTeacher object inside the method, which looks suspect when you are already passing in BusinessLayerTeacher as a parameter.您正在方法内部实例化一个新的 BusinessLayerTeacher 对象,当您已经将 BusinessLayerTeacher 作为参数传递时,该对象看起来很可疑。
Maybe the route mapping isn't working because you're not passing in the right data in the request body.也许路由映射不起作用,因为您没有在请求正文中传递正确的数据。
Maybe you should be using TeacherObj as the parameter type?也许您应该使用 TeacherObj 作为参数类型?
Have a review and give that a try, good luck :-)进行评论并尝试一下,祝你好运:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.