响应重定向不起作用

时间:2016-08-29 08:27:45

标签: c# asp.net-mvc

我在mvc响应重定向中遇到问题。在我的代码中,一切似乎都是正确的,代码进入它,做正确的事情,但页面没有刷新。我的功能由一个按钮触发,该功能有一个响应重定向代码。

这是我的代码。它转到Home / Index,我可以在调试时看到它,但是主页视图没有显示。

注意:首页是登录视图

public class LoginController : Controller
{
    // GET: Login
    [IntranetAction]
    public ActionResult User()
    {         
        return View();
    }

    public void checkAuthentication(UserLoginInfo loginInfo)
    {         
        bool isAuthenticated = new LdapServiceManager().isAuthenticated(loginInfo);
        if (isAuthenticated)
        {      
            Response.Redirect("/Home/Index");
            Response.End();
        }
        else
        {
            Response.Redirect("/", false);
        }         
    }

HomeController索引

public ActionResult Index()
{
    if (IsDbExists())
    {
        _contactList = new List<Contact>();         

        UpdateOperations();
        return View(_contactList);
    }

    Response.Redirect("/Loading/LoadingScreen");
    return null;
}

按钮CSHTML

$("#LoginButton")
    .click(function() {
        if ($("#usernameBox").val() == '') {
            $("#usernameField").addClass('has-error');
            $('#usernameSpan').css("display", "block");
        } else {
            $("#usernameField").removeClass('has-error');           
        }
        if ($("#passwordBox").val() == '') {
            $("#passwordField").addClass('has-error');
            $('#passwordSpan').css("display", "block");
        }
        else {
            $("#passwordField").removeClass('has-error');
        }

        if ($("#usernameBox").val() != "" && $("#passwordBox").val() != "") {

            $.post("/Login/checkAuthentication",
            {
                username: $("#usernameBox").val(),
                password: $("#passwordBox").val()
            });
        }
    });

黄线可以转到索引,但显示屏上没有任何变化

1 个答案:

答案 0 :(得分:0)

你应该使用RedirectToAction

public ActionResult Index()
{
    if (IsDbExists())
    {
        _contactList = new List<Contact>();         

        UpdateOperations();
        return View(_contactList);
    }

    return RedirectToAction("actionname", "controllername");
}

返回null大多是错误的:)

相关问题