TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Praveen Kumar
NA
235
22.1k
Object reference not set to an instance of an object
Apr 11 2020 1:10 AM
Controller
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult Edit(ContactDetailViewModel model)
{
if
(ModelState.IsValid)
{
model.Id = _Login.GetCurrentUserCustomer().Id;
using
(var dbContextScope = _dbContextScopeFactory.Create())
{
Contact contact = model;
contact.ContactAttributes =
new
List<ContactAttribute>();
var user = _Login.GetCurrentUser();
if
(model.Attributes !=
null
)
{
foreach
(var item
in
model.Attributes)
{
if
(item.AddressValue !=
null
)
{
ContactAttribute attribute =
new
ContactAttribute()
{
AttributeValue = item.AddressValue,
Code = item.AddressElement,
Contact = contact
//,
};
_ContactRepo.UpdateContactAttribute(attribute, user);
contact.ContactAttributes.Add(attribute);
}
}
}
try
{
_ContactRepo.UpdateContact(contact, user);
}
catch
(RMException rme)
{
rme.Log();
ModelState.AddModelError(
""
,
"Updating contact failed. Please check your values and try again."
);
return
PartialView(model);
}
dbContextScope.SaveChanges();
}
}
else
{
return
PartialView(model);
}
return
RedirectToAction(
"Index"
,
"Contact"
);
}
Model
public
ContactAttribute UpdateContactAttribute(ContactAttribute attribute, User user)
{
var dbAttribute = DbContext.ContactAttributes.Find(attribute.ContactId);
dbAttribute.AttributeValue = attribute.AttributeValue;
dbAttribute.Code = attribute.Code;
UpdateWithUser(dbAttribute, user.UserId,
"ContactRepo.UpdateContactAttribute"
);
return
dbAttribute;
}
Reply
Answers (
2
)
Hide any div tag from page source or inspect
When i am trying to change some values update not happening