Reputation: 134
I'm checking if a user exists and then I will take him fowards him to main page if exists.
I have successfully invoked the main page action method but the front view doesn't change.
Here is my AJAX request:
$.ajax({
type: "GET",
url: "../../login/login_req",
dataType: "JSON",
data: {
_name: inf.user_name,
_pass: inf.pass,
_isadmin:inf.admin_or_not
},
complete: function (result) {
console.log(result);
}
});
Here is my controller:
public class LoginController : Controller
{
dbhelp dbh = new dbhelp();
// GET: Login
public ActionResult Index()
{
return View("Login");
}
public ActionResult login_req(string _name,string _pass,bool _isadmin)
{
ret retu = new ret();
retu.dt = new System.Data.DataTable();
if (_isadmin)
{
retu= dbh.data_table(string.Format( "select * from users where username='{0}' and password='{1}'",_name,_pass));
}
else {
retu = dbh.data_table(string.Format("select * from employees where e_name='{0}' and e_password='{1}' ", _name, _pass));
}
if (retu.dt.Rows.Count > 0)
{
return RedirectToAction("Index", "Home");
}
}
}
This is the controller that returns the main view that get executed successfully but the front view in browser does not change
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
Upvotes: 0
Views: 68
Reputation:
Sadly, you can't return a RedirectToAction
directly to Ajax. To achieve what you want you should take a look at this question.
Basically, you need to tell the js to call a redirect. There are many ways to do this depending on your specific needs.
Upvotes: 1