About the application of Asp.net MVC 2 Ajax thiskbox

Source: Internet
Author: User

 

When the user sets the password question and answer, the user's password is verified. When the password is incorrect, an error is returned, prompting the user. If the password is correct, navigate to the password setting Question and Answer page.

Here, four pages are used, the template page (Site. master), user information page (LogOnUserControl. ascx), set the password Question and Answer page (ChangePasswordQuestionAndAnswer. aspx), verify the user password page (ValidationUserPassword. ascx ).

Let's take a look at SIte. Master. This page is nested with LogOnUserControl. ascx,

<% Html. RenderPartial ("LogOnUserControl"); %>

 

LogOnUserControl. ascx has a navigation that allows users to set password questions and answers.

 

<% = Html. actionLink ("set password Questions and Answers", "ValidationUserPassword", "Account", new {height = "230", width = "300", modal = true }, new {@ class = "thickbox", title = "verify User Password"}) %>

 

I will use thiskbox to activate and verify the user password page ValidationUserPassword. ascx.

ValidationUserPassword. ascx code

Code

<% @ Control Language = "C #" Inherits = "System. Web. Mvc. ViewUserControl <BobDongCommunity. Modules. Account. ViewModels. ValidationUserPassword>" %>

<Div id = "passwordmain">
<% Using (Ajax. BeginForm ("ValidationUserPassword", "Account", new AjaxOptions {UpdateTargetId = "passwordmain "}))
{%>
<Fieldset>

<Legend> User Password </legend>
<Div class = "editor-label">
<% = Html. LabelFor (model => model. Password) %>
</Div>
<Div class = "editor-field">
<% = Html. PasswordFor (model => model. Password) %>
<% = Html. ValidationMessageFor (model => model. Password) %>
</Div>
<P>
<Input id = "Submit" type = "submit" value = "Logon"/>
</P>
</Fieldset>
<% }%>
</Div>

 

The following code processes ValidationUserPassword. aspx background Action:

 

Code

1 [Authorize]
2 [AcceptVerbs (HttpVerbs. Post)]
3 public ActionResult ValidationUserPassword (ValidationUserPassword model)
4 {
5 If (modelstate. isvalid)
6 {
7 if (membershipservice. validateuser (user. Identity. Name, model. Password ))
8 {return JavaScript ("document. Location = '/account/changepasswordquestionandanswer '");
9 // return redirecttoaction ("changepasswordquestionandanswer ");
10}
11 else
12 {
13 modelstate. addmodelerror ("password", "Incorrect password. Please try again! ");
14}
15}
16 return View ();
17}
18

 

Running result description:

First activate the authentication password thickbox layer and enter the password

The password is incorrect. The expected result is displayed.

When the password is correct, we get this result.

For this reason, AJAX is used for password verification. When the password is correct, it updates ChangePasswordQuestionAndAnswer. aspx to ValidationUserPassword. ASPX.

Now the problem arises. Instead of updating it, I directly jump to ValidationUserPassword. ASPX, just like this.

After the problem is solved, return JavaScript ("document. location = '/Account/logon'") from the background '");

In this way, the original layer will not be updated.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.