I'm new to javascript and MVC I'm working on a sample application containing a sign up page and I'm using ajax to done the process my current code is given below
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;
}
and its working fine but I want to know that is there any way to pass these values as a single object like in C# forgive me if this question is too silly
serverside code
[HttpPost]
public ActionResult Create(User user)
{
UserDL newUser = new UserDL();
newUser.SignUp(user);
return Json(new { success = true });
}
and also I want to know is there any way to combine these values directly with my server side object
User.cs
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; }
}