【发布时间】:2012-02-11 17:55:01
【问题描述】:
1。
我有一个主页(主页/索引)。在这里选择语言。
这里的网址是:"localhost:xxxx".
2。
选择语言后,以下是登录页面(账号/索引)
这里的网址是:"localhost:xxxx/Account/Index?language=en-US".
3。 输入数据(用户名/密码)并单击登录按钮时,重定向到用户/索引,但 url 保留在 Account/LogOn
我的表格:
<% using (Html.BeginForm("LogOn", "Account")) { %>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Username:</label>
<%: Html.TextBoxFor(m => m.Username, new { placeholder = "Username" })%>
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Password:</label>
<%: Html.PasswordFor(m => m.Password, new { placeholder = "Password" })%>
</div>
<fieldset class="ui-grid-a">
<div class="ui-block-a"><button type="reset" data-theme="d">Reset</button></div>
<div class="ui-block-b"><button type="submit" data-theme="b">Log On</button></div>
</fieldset>
<% } %>
账户管理员:
[HandleError]
public class AccountController : Controller
{
public ActionResult Index(string language = "es-Es")
{
return View();
}
[HttpPost]
public ActionResult LogOn(UserModel user)
{
FormsAuthentication.SetAuthCookie(user.Username, false);
return RedirectToAction("Index", "User");
}
public ActionResult LogOff()
{
return View();
}
}
全球.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
如何使url为:localhost:xxxx/User/Index ?
【问题讨论】:
-
只需将 data-ajax="false" 添加到表单中,无需任何丑陋的修复即可工作:)
标签: c# asp.net-mvc asp.net-mvc-3 redirect