2013-04-06 24 views

回答

5

你的两个面板不允许用户在一个或另一个之间切换,所以我假定你有一个“前奏”视图的选项要么登录或注册。对?在这种情况下,不需要使用Javascript/Ajax进行客户端面板切换。您的“介绍”视图可以将参数传递给控制器​​操作,以定义是否需要登录或注册视图。

例如:

// RouteConfig.cs 
routes.MapRoute(
    name: null, 
    url: "login-register/{action}", 
    defaults: new { controller = "Authentication"}, 
    constraints: new { action = @"(SignIn|Register)" } 
); 

// AuthenticationController.cs 
public ActionResult SignIn() 
{ 
    ... 
    return View(); // Will return the Authentication\SignIn.cshtml view 
} 

public ActionResult Register() 
{ 
    ... 
    return View(); // Will return the Authentication\Register.cshtml view 
} 
+0

你是否知道这是否会受到使更新面板开始流行的回发闪烁的“影响”? – plntxt 2013-06-12 17:34:36

5

更新面板在ASP.NET MVC中并不存在。在人们实际意识到使用手写jQuery ajax进行部分页面更新之前,它曾经存在于ASP.NET Web窗体开发世界中。

您可以使用jQuery ajax方法将表单数据发布到操作方法,并根据需要对页面进行部分页面更新。您也可以考虑根据需要使用部分视图(返回页面的一部分)。

在您的情况下,您可以创建2个部分视图进行登录和注册,并将其包含在主视图中,以使您的代码更加可重用。

<h1>Login or Register</h1> 
<div> 
    @Html.Partial("Login") 
</div> 
<div> 
@Html.Partial("Register") 
</div> 
+0

我用了这个想法。谢谢。 – 2013-04-06 12:46:34