vicky t

vicky t

  • NA
  • 2
  • 539

Unable to add variable values to DB using TryUpdateModel

Feb 5 2020 5:03 AM
I have a variable which has values and I am trying to add to DB using TryUpdateModel and eventually it doesn't happen.
 
Getting below error message.
  1. [HttpPost]  
  2. public ActionResult CreateAccount(FormCollection collection)  
  3. {  
  4. string msg = string.Empty;  
  5. try  
  6. {  
  7. var accountdetail = new AccountDetail();  
  8. TryUpdateModel(accountdetail);  
  9. AccountRepository userRepo = new AccountRepository();  
  10. if (userRepo.CreateUser(EntityHelper.InitializeUser(accountdetail, 0)))  
  11. return Json(new { Result = "Success", InfoMsg = msg });  
  12. else  
  13. msg = "Error returned";  
  14. }  
  15. catch (Exception ex)  
  16. {  
  17. msg = ex.Message;  
  18. }  
  19. return Json(new { Result = "Failed", InfoMsg = msg });  
  20. }  
Error Message:
 
Property set method not found.
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at PerpetuumSoft.Knockout.KnockoutUtilities.ConvertData(Object data)
at PerpetuumSoft.Knockout.KnockoutUtilities.ConvertData(Object data)
at PerpetuumSoft.Knockout.KnockoutModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model)
at WebApp.Controllers.AccountController.CreateAccount(FormCollection collection) in C:\Code\AccountController.cs:line 166
Exception is thrown at this line
TryUpdateModel(accountdetail);
Really appreciate any inputs.