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
Anilananda Chakrabortty
NA
425
78.1k
MVC Edit problem
Aug 30 2018 12:02 AM
Hi ,
I have created a form with MVC with the field :
[Id]
,[FirstName]
,[Username]
,[Email]
,[Password]
,[Salt]
,[Designation]
Now i want to edit this data in the Edit view without including
,[Password]
,[Salt]
so i remove those two field form the edit view . but after edit when i am trying to update those two field, its becoming NULL value ([Password],[Salt]) .
Now here is the problem ... I dont want to edit those field . i want password and salt value would be the same value which was inserted in the time of Creation.
in the edit field only
[Id]
,[FirstName]
,[Username]
,[Email]
,[Designation]
i want.
here is my code for edit :
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult Edit([Bind(Exclude =
"Password,Salt"
)] User user)
{
if
(ModelState.IsValid)
{
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return
RedirectToAction(
"Index"
);
}
return
View(user);
}
i also written this code....
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult Edit(
int
? Id, User user)
{
if
(ModelState.IsValid)
{
User Objuser = db.User.Single(x => x.Id == id);
user.Password = Objuser.Password;
user.Salt = Objuser.Salt;
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return
RedirectToAction(
"Index"
);
}
return
View(user);
}
both the code is given error.
can anyone help me out plz ?
Reply
Answers (
1
)
Doubts about using IF and else
How to create table columns dynamically in entityframework