Mike or Imar:
I am trying to pass a database row Id in an email, so the user can see the entire contents of the row (online exam results) in page named
Final_Results.cshtml.
The user gets an email when a student submits an exam. The email code runs just fine and but was a challenge this morning!
I figured out how to send the user to another page (listing all the exams) but I want also to provide the option for the user to link exam results for the (specific) student who just submitted the exam in the email.
So far I have not been able to pass the database Id to the
Final_Results.cshtml using the code below. I think my problem is in the
URL syntax of passing the row ID. I've done this before with ColdFusion using CFMAIL, but this seems more of a challenge!
Thanks ahead of time!
Code:
@{
var postId = Request["Id"].AsInt(0);
var db = Database.Open("CCS") ;
var post = db.QuerySingle("SELECT * FROM FinalExtExam WHERE Id = @0;", postId);
if(post == null) {
<div>Sorry, that post was not found!</div>
}else{
var FirstName = post.FirstName;
var LastName = post.LastName;
var customerEmail = "[email protected]";
var AdminEmail = "[email protected]";
var debuggingFlag = false;
// Initialize WebMail helper
WebMail.SmtpServer = "smtprelay.MyInstitution.edu";
WebMail.SmtpPort = 25;
WebMail.UserName = "jj42";
WebMail.Password = "Celtic";
WebMail.From = "[email protected]";
// Send email;
WebMail.Send(to: customerEmail,
subject: "New CCS Exam Submitted by Dr. " + LastName,
body: "A CCS Final Exam was just <a href='http://localhost:30053/Final_Results.cshtml?Id=postId'>submitted</a> by Dr. " + LastName
);
}
}