1
I have a registration screen that should be validated by various business rules, when the user does Submit I wanted to leave a page with a message for example, "Validating, wait". I tried to do this with asynchronous delegates, I did a test project just to test if it would work, the logic on the server even worked, He called a method that puts a Sleep in the thread to symbolize the validation time and called the method that brings the wait screen the problem is that the screen does not appear, despite being called. Check the controller code
public delegate int Completo();
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
//chama o metodo trabalhar que simula a espera e coloca a action ValidacaoCompleto para ser executada quando o metodo
//Trabalhar estiver concluído
public void Validacao()
{
Numero n = new Numero();
Completo c = new Completo(n.Trabalhar);
IAsyncResult result = c.BeginInvoke(new AsyncCallback (ValidacaoCompleto), null);
TelaValidacao();
}
//chama a View de espera
public ActionResult TelaValidacao()
{
return View();
}
//esse metodo chama a View de validação concluida, não chamei a View direto no metodo TelaValidacao
//por que o tipo de retorno do metodo que será chamdo pelo delegate assincrono não pode ser Actionresult
public void ValidacaoCompleto(IAsyncResult result)
{
ChamarTelaFinal();
}
//chama a View de validação concluida
public ActionResult ChamarTelaFinal()
{
return View();
}
}
really, using ajax is simpler. In ASP.NET MVC has the ajax.beginform method that sends the form all via ajax, I will post the full code of how I did.
– Alan Almeida