通过弹出窗口注册并在此弹出窗口中传递结果
register via popup and pass result in this popup
我通过弹出窗口(Jquery UI对话框)实现了注册和登录。这是我的UserNavigation
控制
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<script type="text/javascript">
$(document).ready(function () {
$("#loginDialog").click(function () {
$.get("/Account/LogOn",
function (htmlResult) {
$("#logon").remove();
$("#container").append(htmlResult);
$("#logon").dialog({ modal: true });
}
);
return false;
});
$("#registerDialog").click(function () {
$.get("/Account/Register",
function (htmlResult) {
$("#registration").remove();
$("#container").append(htmlResult);
$("#registration").dialog({ modal: true });
}
);
return false;
});
});
</script>
<div id="userNavigation">
<%
if (Request.IsAuthenticated)
{
%>
<a href="/users/mr.freeman/profile" class="username"><span><%=Page.User.Identity.Name %></span><i class="icon iUser"></i></a>
<ul class="headLine_link">
<li><a href="#">Profile settings</a></li>
<li>
<%= Html.ActionLink("Log off", "LogOff", "Account", null, new { @class = "exit" })%></li>
</ul>
<%
}
else
{%>
<ul class="headLine_link">
<li><%=Html.ActionLink("Register", "Register", "Account", null, new {id = "registerDialog"})%></li>
<li><%=Html.ActionLink("Log On", "LogOn", "Account", null, new {id = "loginDialog", @class = "username" })%></li>
</ul>
<%}%>
</div>
它运行良好。但是,我希望当注册成功时,在同一窗口中显示消息。我该怎么做?
这是我的控制器:
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
//FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
第二个问题:如果用户在需要授权的网站上执行某些操作,则显示登录屏幕(如果用户未获得授权)。
我尝试使用Authorize
属性,但不起作用。
谢谢。
更新:注册视图:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<DT.KazBilet.Web.Portal.Models.RegisterModel>" %>
<div id="registration">
<h2>Create new account</h2>
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true, "Error. Try again.") %>
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
<%: Html.LabelFor(m => m.UserName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(m => m.UserName) %>
<%: Html.ValidationMessageFor(m => m.UserName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(m => m.Email) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(m => m.Email) %>
<%: Html.ValidationMessageFor(m => m.Email) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(m => m.Password) %>
</div>
<div class="editor-field">
<%: Html.PasswordFor(m => m.Password) %>
<%: Html.ValidationMessageFor(m => m.Password) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(m => m.ConfirmPassword) %>
</div>
<div class="editor-field">
<%: Html.PasswordFor(m => m.ConfirmPassword) %>
<%: Html.ValidationMessageFor(m => m.ConfirmPassword) %>
</div>
<p>
<input type="submit" value="Register" />
</p>
</fieldset>
</div>
<% } %>
</div>
将Html.BeginForm()
更改为Ajax.BeginForm()
,则响应将在弹出窗口中呈现,而不是在整个页面中呈现。
从estetic的角度来看,您还应该将Html.ValidationSummary
从注册表中移出,因为它会随着Html.ValidationMessageFor
一起更新错误,并且您不需要将该信息加倍,最好将其放在窗体之前。Html.ValidationSummary
应该用于显示控制器的错误。
相关文章:
- 为自定义网站创建JavaScript搜索框,创建显示搜索结果的弹出窗口
- 防止多次显示弹出窗口.Ajax添加结果已在DOM中注册
- 使用HTML搜索,需要JavaScript来搜索数组并在新窗口中返回结果
- 无法在新窗口中打开 javascript 搜索引擎结果
- 如何在带有复选框按钮的 HTML 弹出窗口中显示结果
- 如何使用 ajax 在 showModelDialog 中提交表单后在父窗口中显示结果
- 打开对话框,其中包含在使用 magnificPopup 构建的弹出窗口中跟随 URL 返回的结果
- 在jQuery窗口外使用FileReader中的结果值
- 使用AJAX结果动态更新引导弹出窗口
- 从弹出窗口中使用php和javascript传递多个MySQL结果集
- 当搜索没有结果时抛出弹出窗口
- 通过弹出窗口注册并在此弹出窗口中传递结果
- 谷歌地图信息窗口在不同的标记上给出相同的结果
- 点击弹出窗口中的按钮搜索结果
- 模态对话框返回值未定义-将结果发送到父窗口
- 在新选项卡或窗口显示表单提交的结果
- 从弹出窗口返回结果
- 使用窗口.反复打开会产生意想不到的结果
- 结合_.记住和_.节流以限制函数调用,并在一个时间窗口内缓存结果
- 无法在弹出式模式窗口中显示SQL结果