I'm trying to submit a form to my account controller. I am getting the following errors: I've looked everywhere and cannot seem to find the solution.
1
$ and JQuery are not defined.
2
server responding with a 404 error (which I'm sure is related to #1)
NOTE: I understand my controller is not setup to handle the request at the moment. What I need assistance with is trying to get the request through to the server.
Thanks Stack in advance for your help!
View:
<reference path="jquery.min.js" />
<reference path="kendo.all.min.js" />
@{
ViewBag.Title = "Register";
}
@section styles {
<link href="@Url.Content("~/Content/Views/Form.css")" rel="stylesheet" type="text/css" />
}
<script type="text/javascript">
$('#"ButtonSubmitForm"').click(function () {
submit();
}
);
</script>
<div class="middle-center">
<div class="form-center">
@{
Html.Kendo().Window()
.Name("registerForm")
.Title("UserProfileWndw")
.Draggable()
.Width(500)
.Actions(actions => { })
.Iframe(true)
.Content(
@<text>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
</li>
<li>
@Html.LabelFor(m => m.EmailAddress)
@Html.TextBoxFor(m => m.EmailAddress)
</li>
<li>
@Html.LabelFor(m => m.OrganizationId)
@Html.DropDownListFor(m => m.OrganizationId, new SelectList(ViewBag.Organizations, "OrganizationId", "Name"), string.Empty)
</li>
</ol>
<input type="submit" id="ButtonSubmitForm" value="Add user" class="k-button" />
<!-- clear button-->
<!-- cancel button-->
</fieldset>
}
</text>
).Render();
}
</div>
</div>
function submit() {
$(document).ready(function(){
var form = $("#registerForm");
$.ajax({
cache: false,
async: true,
type: "POST",
url: "Account/AdminReg/",
data: form.serialize(),
success: function (data) {
alert(data);
}
});
}
)
}
</script>
Controller:
public ActionResult AdminReg(Register model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Organization_OrganizationId = model.OrganizationId, IsApproved = false, EmailAddress = model.EmailAddress }, true);
// add user to org user group if specified
Organization org = db.Organizations.Include("Groups").Include("Groups.Members").SingleOrDefault(o => o.OrganizationId == model.OrganizationId);
if (org != null)
{
UserProfile newUser = db.UserProfiles.Single(u => u.UserName == model.UserName);
org.Groups.Single(g => g.Name == "Users").Members.Add(newUser);
db.SaveChanges();
}
if (User.IsInRole("Admin") || User.IsInRole("Administrators"))
{
return RedirectToAction("ReadUsers", "UserManagement");
}
//WebSecurity.Login(model.UserName, model.Password);
return RedirectToAction("RegistrationSuccessful", "Account");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
return PartialView("UserAddAdminTemplate");
}