Currently, I am new to javascript and MVC. I am developing a sample application with a sign-up page where I am using ajax for the process. The code snippet below shows my current implementation:
function create() {
var user_name = $("#txtUser").val();
var pass = $("#txtPass").val();
var email = $("#txtEmail").val();
var phone = $("#txtPhone").val();
var city = $("#txtCity").val();
var state = $("#txtState").val();
var zip = $("#txtZip").val();
$.ajax({
url: '/EmberNew/Home/Create',
type: 'POST',
data: { user_name: user_name, pass: pass,email:email,phone:phone,city:city,state:state,zip:zip },
success: function (response) {
alert("success");
}
});
return false;
}
Although this setup is functional, I am curious if there is a way to pass these values as a single object similar to how it's done in C#. Apologies if this question seems too basic.
Server-side code excerpt:
[HttpPost]
public ActionResult Create(User user)
{
UserDL newUser = new UserDL();
newUser.SignUp(user);
return Json(new { success = true });
}
I also want to explore the possibility of combining these input values directly with my server-side object.
User class structure:
public class User
{
public virtual int ID { get; set; }
public virtual string UserName { get; set; }
public virtual string Password { get; set; }
public virtual string EmailID { get; set; }
public virtual int Phone { get; set; }
public virtual string City { get; set; }
public virtual string State { get; set; }
public virtual int Zip { get; set; }
}