如何从asp.net中的另一个ActionResult调用ActionResult

时间:2013-11-07 07:08:02

标签: asp.net-mvc

我正在为用户注册,显示,登录等创建一个网站。我目前正在尝试显示已登录用户的详细信息。但是在登录的actionResult中,我不知道如何调用actionResult显示?我是asp.net的新手。我需要建议

public ActionResult login()
{
    try
    {
        return View();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

[HttpPost]     
public ActionResult login(DEntities.Users user)
{
    try
    {
        services.CheckUser(user);
        controlsuccess = services.servicesuccess;
        if (controlsuccess == true)
        {

            return RedirectToAction("display");             
            //return View("display");
        }
        else
        { 
            return HttpNotFound();
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

public ActionResult display()
{
    return View();
}

[HttpPost]
public ActionResult display(int id = 0)
{
    try
    {
        DEntities.Users user = services.GetUserbyId(id);
        return View(user);

    }
    catch (Exception ex)
    {
        throw ex;
    }
}

1 个答案:

答案 0 :(得分:13)

[HttpPost]

中删除display action属性

如果两个动作都在同一个控制器中,那么只需传递动作名称

return RedirectToAction("display", new { id = 1 });

或者如果操作在不同的控制器中,则只需传递动作名称返回

RedirectToAction("display", "controlername", new { id = 1 });

或者,如果有必要使用[HttpPost],请使用以下链接 Click here

相关问题