Hi to all,
Basically, I have an HTML Form and would want to pass the data from the form to n asp.net mvc controller, then the controller would return an XML for client side manipulation.
Here is my initial code:
Client:
$(function() {
$('#btnSubmit').click(function() {
$.post('/Home/Create', $('form').serialize(), function(data) {
$('#entryForm').remove('form');
// $('#entryForm form').html(data);
alert(data);
$(data).find('Person').each(function() {
alert($(this).attr('Lastname').val());
});
}, "xml");
return false;
});
});
Here is the code for my Controller action:
public ActionResult Create(Person p)
{
//Person p = new Person();
//p.Lastname = lastname;
//p.Firstname = firstname;
//p.Middlename = middlename;
// this returns XML Data
return new XmlResult(p);
}
When I run and debug, I get a message that says "attr(..) is null or not an object. Can you please help me identify what I'm doing wrong here? Any suggestion would also be gladly appreciated, as I am still trying to learn web development using ASP.NET MVC.
Thanks
Most