I'm not entirely sure if this is the best way to word it, however, I'm having a little trouble working out how to achieve. What I have is a page with a form on for editing a user's details.
The page itself sits on /User/Edit/1234 where 1234 is the employee number.
On that page there is a reset password link which opens the following jQuery UI dialogue box.
<div id="dialog-confirm" title="Are you sure?">
<form name="passReset" id="passReset" action="/User/Reset/<%=Html.ViewData("EmployeeNumber")%>" method="post">
<div id="reset1"><%=Html.ViewData("Name")%>'s password will be reset to 11111. You need to notify them that
they will need to change their password immediately or the account will be locked out. <br /> <br />
If you are sure you wish to proceed. Type the word <b>"YES"</b> in the box below and click OK.
<div align="center">
<%=Html.ValidationMessage("confirmResetText")%>
<input type="text" id="confirmResetText" style="width: 45px;"/><input type="submit" value="OK" />
</div>
</div>
</form>
</div>
What I would like to do is submit that form to an Action (in this instance /user/reset/1234) and return the result (Success, Fail or a validation message) to the dialog without the user ever leaving the page.
The code for the action I have would do what I'm after if I was submitting back to the same action as the page, but I'm not, and this is where I'm stuck.
The code I have is:
<AcceptVerbs(HttpVerbs.Post)> _
Function Reset(ByVal employee As String, ByVal collection As FormCollection)
If ModelState.IsValid Then
If collection("confirmResetText") <> "Yes" Then
ModelState.AddModelError("confirmResetText", "You didn't enter 'YES'.")
End If
'if data doesn't pass all rules, take them back to the form
If (Not ModelState.IsValid) Then
Return View(collection)
End If
ModelState.SetModelValue("confirmResetText", New ValueProviderResult(ValueProvider("confirmResetText").AttemptedValue, collection("confirmResetText"), System.Globalization.CultureInfo.CurrentCulture)) 'First Name
Dim myArea = (From a In db.secUserInfos _
Where a.EmployeeNumber = User.Identity.Name.ToString).SingleOrDefault
Dim uEditable As secUserInfo = gsecRepository.CheckIfUserCanBeEdited(employee, myArea.AreaID).SingleOrDefault
'check if user can be edited by you.
If uEditable Is Nothing Then
Return Redirect("/Home")
Else
Try
db.aspnet_Membership_SetPassword("/", employee, "11111", "11111", DateTime.Now, 0)
Catch ex As Exception
Response.Write(ex.Message)
End Try
Return Redirect("/User/Edit/" & employee)
End If
End If
End Function
So how do I go from this to what I'm actually trying to achieve? I have considered JSON as a solution, but my knowledge regarding that is pretty limited.
Any help is greatly appreciated.