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
Hamza Shah
NA
87
22.6k
Show a message through a controller “Attendance is already marked”
Nov 12 2020 11:54 PM
I'm working on online attendance portal, In which I've set a condition in a controller that user can't marked attendance twice a day. They are only allowed to mark attendance once per day. So I want to show a message on view page "Create" that "Attendance is already marked" if employee is marking the attendance second time on a same date. I've set an alert message but I want to show a message on view page from where employee is marking the attendance .I've searched it a lot but can't find any better one.
Here's my Controller Code
[Authorize]
public
ActionResult Create()
{
Employee employee = JsonConvert.DeserializeObject<Employee>(User.Identity.Name);
return
View(
new
Attendance() { Emp_Id = employee.Emp_Id });
}
[HttpPost]
public
ActionResult Create(Attendance attendance)
{
if
(ModelState.IsValid)
{
try
{
var attdate = attendance.Date;
var nextdate = attdate.AddDays(1);
var id = Convert.ToInt32(Session[
"UserID"
]);
var isExist = db.Attendance.FirstOrDefault(i => i.Emp_Id == id && i.Date == attdate && i.Date < nextdate);
if
(isExist !=
null
)
{
//Here i set the alert but i want to show message on view page.
return
Content(
"<script language='javascript' type='text/javascript'>alert('Your Attendance is Already Marked');</script>"
);
}
else
{
//var res = tempDate.Date;
db.Attendance.Add(attendance);
db.SaveChanges();
}
}
catch
(Exception ex)
{
Console.WriteLine(ex.InnerException.Message);
}
}
return
RedirectToAction(
"Index"
,
"Attendance"
);
}
Reply
Answers (
1
)
Date Formatting in Text Box Content
ASP.NetCore3.1 and OData