“Controller, Action, Model” not all code paths return a value

前端 未结 3 454
生来不讨喜
生来不讨喜 2021-01-28 12:45

I am really confused by this error "not all code paths return a value" on my action PostResponse. I have stared at my model, controller and view for hours and I think

3条回答
  •  离开以前
    2021-01-28 13:21

    try

       [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult PostResponse([Bind(Include = "UserId,QuestionID,Answer,Source,Status,DateStamp")] Response response)
    {
        if (ModelState.IsValid)
        {
            db.Responses.Add(response);
            db.SaveChanges();
        }
        else{
            return View("Error");
        }
    
    }
    

提交回复
热议问题