TryUpdateModel is not working for new Record on ASP.NET MVC Page?

Posted by Rita on Stack Overflow See other posts from Stack Overflow or by Rita
Published on 2010-05-20T22:26:40Z Indexed on 2010/05/20 22:30 UTC
Read the original article Hit count: 786

Filed under:
|

Hi

I have a customer Registartion page using ASP.NET MVC with fields like FirstName, LastName, Address from AddressDetail Table.

When i create a new object for CustomerMaster and trying to update the fields using TryUpdateModel, it is not updating.

But the TryUpdateModel is working fine on the Edit Profile Page and that particular record is referenced.

CODE on Registartion Page:

    AddressDetail add = new AddressDetail();
bool status = TryUpdateModel<AddressDetail>(add, "addr", new[] { "FirstName", "LastName", "Address_1", "Address_2", "ZipCode", "City", "Phone", "Fax" }, formData);

CODE on Edit Profile Page:

AddressDetail addr = (from a in miEntity.AddressDetail
                          where a.AD_Id == 20
select a).First();
bool rc = TryUpdateModel<AddressDetail>(addr, "addr", new[] { "FirstName", "LastName", "Address_1", "Address_2", "ZipCode", "City", "Phone", "Fax" }, formData);

Does anybody run into same issue with TryUpdateModel? Doesn't it update the Model for New Record?

Thanks

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2