我尝试在另一个方法中调用返回View
的方法,但是在同一个控制器中。有我的代码:
public ActionResult GetAnswer(List<PossibleAnswerVM> possibleAnswers)
{
if (IsLastQuestion(possibleAnswers.FirstOrDefault().IdQuestion))
{
return Index();
}
return null;
}
[HttpGet]
public ActionResult Index()
{
IEnumerable<Anketa> anketas = Manager.SelectAnketa();
return View(anketas);
}
还有一个调用GetAnswer()
@using (Ajax.BeginForm("GetAnswer", "Survey", FormMethod.Post,
new AjaxOptions { InsertionMode = InsertionMode.Replace }))
{
<input type="submit" value="Ответить"
onclick="answerClick(@Model.FirstOrDefault().OrdQuestion);"
class="btn btn-default" />
}
我也试过RedirectToAction()
并从另一个控制器调用方法
我将不胜感激任何帮助。
答案 0 :(得分:0)
试试这个。
public ActionResult GetAnswer(List<PossibleAnswerVM> possibleAnswers)
{
if (IsLastQuestion(possibleAnswers.FirstOrDefault().IdQuestion))
{
IEnumerable<Anketa> anketas = Manager.SelectAnketa();
return View("VIEWNAME", anketas);
}
return null;
}
private static bool IsLastQuestion(int idQuestion)
{
var returnValue = false;
Question question = Manager.GetQuestion(idQuestion);
List<Question> questions = Manager.SelectQuestions(question.idAnketa);
if (questions.Count == Manager.GetCountQuestionsAnswered(question.idAnketa, SessionUser.PersonID))
{
returnValue = true;
}
return returnValue;
}