1
I have a Controller
:
[HttpPost]
public ActionResult Login(string pUsuario, string pSenha)
{
usuario oUsuario = modelOff.usuarios.Where(p => p.usuario1 == pUsuario && p.senha == pSenha).SingleOrDefault();
if (oUsuario == null)
return IR_PARA_ACTION_1;
else
return IR_PARA_ACTION_2;
}
How to select a Action
according to the outcome of my if
?
I get an error that not all paths return a value
– Italo Rodrigo
@Italorodrigo so you didn’t use the code exactly as LINQ posted. His code always returns something.
– Oralista de Sistemas
The error is on the line
public ActionResult Login(string pUsuario, string pSenha)
in the wordLogin
– Italo Rodrigo
The semicolon was missing, @Italorodrigo
– Jéf Bueno
The code ran, but I’m getting a 404 error when sending the form. I’m using the code like this:
if (oUsuario == null) { return RedirectToAction("Index"); } else { return RedirectToAction("Login"); }
– Italo Rodrigo
So it’s because the action doesn’t exist. "index" is in the same controller?
– Jéf Bueno
To
Index
is what I start with. It makes the mistake when I go toLogin
. Just one question:Action
is the same asView
?– Italo Rodrigo
No. Action is the method, view is the cshtml file. It would be good to read this: What are the actions of a controller?
– Jéf Bueno
So I’m doing it wrong. My idea is to return a
View
. I’ll see if I can adapt the code here. Thank you.– Italo Rodrigo
@Italorodrigo Just create an action for this view.
– Jéf Bueno