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

前端 未结 3 459
生来不讨喜
生来不讨喜 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条回答
  •  旧时难觅i
    2021-01-28 13:15

    Worked it out; but it was almost from scratch, as I created a new ViewModel and used that to populate the responses.

            [HttpPost]
        public ActionResult ViewQuestion([Bind(Include = "QuestionId, Answer, UserId")] ResponseViewModel responseViewModel)
        {
    
            Response re = new Models.Response();
                re.Answer = responseViewModel.Answer;
                re.UserId = responseViewModel.UserId;
                re.QuestionId = responseViewModel.QuestionId;
                re.DateStamp = System.DateTime.Now;
                db.Responses.Add(re);
                db.SaveChanges();
    
            return RedirectToAction("ViewQuestion");
        }
    

    Thanks for your input as your comments got the old head working again. Thanks!

提交回复
热议问题