Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
give custom validation in controller action method in aspmvc
athira k
Apr 22 2017 2:39 PM
223
Reply
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
asp.net protect videos from downloaded by website users ??
DropDownList5' has a SelectedValue which is invalid