I'm just beginning ASP.NET, and getting very comfortable with the MVC stuff, thanks to my PHP/Rails MVC background. Excuse me if these are simple questions, but I've been banging my head against them all day, so would appreciate some guidance.:
Question 1:
I have an action which saves a form to the server, then should update the appropriate record with the server path to the file. I can upload the file OK; it saves fine. However, I cannot get the record to update. I get a "Specified cast is not valid" exception. In the code below I have removed the upload logic.
public void AddFile(int id)
{
data.Candidate = db.Candidates.Single(x => x.ID == id);
// File Upload Logic
// SavedPath is a string representing the server file location
data.Candidate.CV = SavedPath;
//This bit doesn't work...
db.SubmitChanges();
}
Question 2
After the record updates, I would like to send the user back to the page they came from (not just render the view, which would be easy). As I'm pulling out the same data (candidate), surely this is easy to do and I'm just missing something obvious. At the moment I'm rendering a new view which has a response.redirect in the code-behind constructor. It works, but it's not very elegant... Any better suggestions?
Thanks in advance for any help :-)