0

i am creating a web app and i want to redirect page on button click and i used all the textbox and button as input field i can't see much about this on internet, how can i redirect to another page on button click(if id and password is validated)

for e.g i did all sql related queries in modal and i am passing true or false from modal (if true(redirect to login page))(if false(redirect to signup page)) what i need to do on my controller

    [HttpPost]
    public ActionResult testlogin(string username, string password)
    {
        // called my modal here and creates its object(modal m=new modal();) 
        //what to do now
    }

in my modal i have sql query like

`sql command cmd=new sqlcommand("select * from empdet where empid='"+user+"' and pass='"+password+"'",con);
con.open();
SqlDataAdapter da=new SqlDataAdapter(cmd);
dataset ds=new dataset();
da.fill(ds);
if(ds.tables[0].rows.count>0)
{
bool true;
}
else
{
bool false;
}
con.close();
bool = Convert.ToBoolean(cmd.ExecuteReader());
return user;`

if bool returns true, the page should be redirect to welcome page otherwise redirect to login page

2

2 Answers 2

0

Try this one:-

[HttpPost]
public ActionResult testlogin(string username, string password)
{
    // called my modal here and creates its object(modal m=new modal();) 
    bool loginResult= call your model method
    if(loginResult)
    {
         return RedirectToAction("Welcome","Home");
    }
    else
    {
         return RedirectToAction("Login","Home");
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

use can use

[HttpPost]
public ActionResult testlogin(string username, string password)
{
   return Response.Redirect("../HomeIndex?Option=Please_log_in_as_user");
}

or

[HttpPost]
public ActionResult testlogin(string username, string password)
{
   return RedirectToAction("AddressDelivery", "BuyOnline", new { Option = "SetAsDeliveryAddress" });

// first one is action, second is controller name, then if needed parameters
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.