As the title for my question states, i wish to post a registration form to my controller via ajax instead of a submit button within a BeginForm
.
HTML looks like this:
@Html.LabelFor(m => m.Email)<br />
@Html.TextBoxFor(m => m.Email)<br />
@Html.LabelFor(m => m.Password)<br />
@Html.TextBoxFor(m => m.Password)<br />
@Html.LabelFor(m => m.Name)<br />
@Html.TextBoxFor(m => m.Name)<br />
<p>
<button type="submit" id="sbmt">Register</button>
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
</p>
My controller method looks like this:
public ActionResult Registration(Users model)
{
//code for registration of user
}
i want my ajax to pass just the model to my controller. In other words, i dont want to declare multiple string arguments in my controller.
My ajax so far looks something like this:
$("#sbmt").click(function (e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: "@Url.Action("Register", "Auth")",
data: { WHAT SHOULD I PASS HERE? },
}).done(function (res) {
if (res.status === "success") {
$("#MailFoot").hide();
$("#ty").text("Thank you!");
}
else {
alert("Error sending email");
}
});
});
I have no idea how i should wrap my data and pass it to my controller. Any help is therefore appreciated.