[英]Why I can not call method from another one in the same controller?
I try to call method that returns View
inside of another method, but in the same controller. 我尝试调用在另一个方法中返回View
的方法,但是在同一个控制器中。 There is my code: 有我的代码:
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);
}
And there is the form which call GetAnswer()
并且有一个调用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" />
}
Also I have tried RedirectToAction()
and call methods from another controller. 我也尝试过RedirectToAction()
并从另一个控制器调用方法。
I would appreciate any help. 我将不胜感激任何帮助。
Try this. 尝试这个。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.