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
athira k
NA
140
53.5k
give custom validation in controller action method in aspmvc
Apr 22 2017 2:39 PM
I am doing validation in controller part action method and I got stuck at a point that to give validation for name by checking the condition that the name should not appear already in the table. I have tried many conditions but always getting some error. can anyone please help me to find solution for my problem ???
controller
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "Id,Name")] Student student)
{
TempData["name"] = student.Name;
var show = db.Students.Select(e => e.Name).ToList();
if (show == TempData["name"])
{
ModelState.AddModelError("Name", "Name already exists");
}
f (ModelState.IsValid)
{
db.Students.Add(student);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(student);
}
this is my controller part where I nned to give validation
Reply
Answers (
1
)
asp.net protect videos from downloaded by website users ??
DropDownList5' has a SelectedValue which is invalid