Click here to Skip to main content
15,867,568 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionUsing Base Model in Shared View Pin
Farhad Eft2-Jun-17 23:16
Farhad Eft2-Jun-17 23:16 
AnswerRe: Using Base Model in Shared View Pin
User 41802543-Jun-17 3:40
User 41802543-Jun-17 3:40 
GeneralRe: Using Base Model in Shared View Pin
Farhad Eft3-Jun-17 5:39
Farhad Eft3-Jun-17 5:39 
QuestionHow codeproject registration page showing client timezone as selected in dropdown Pin
Mou_kol2-Jun-17 0:07
Mou_kol2-Jun-17 0:07 
AnswerRe: How codeproject registration page showing client timezone as selected in dropdown Pin
Richard Deeming2-Jun-17 1:14
mveRichard Deeming2-Jun-17 1:14 
GeneralRe: How codeproject registration page showing client timezone as selected in dropdown Pin
Mou_kol2-Jun-17 2:29
Mou_kol2-Jun-17 2:29 
QuestionNeed some help in binding DataTable that's returning from Web Api with an Html table using jquery Pin
indian14330-May-17 8:08
indian14330-May-17 8:08 
Questiontrouble sending message to the view from controller Pin
Hamiltonian1327-May-17 22:40
Hamiltonian1327-May-17 22:40 
Hi all,

I am having trouble sending a success/fail message to a view from my controller. I have a file upload section of my website. User chooses file, presses upload button and file is saved in a folder.

My Controller code:
public ActionResult UploadFiles(int? id)
        {
            CI cI = db.DataBase.Find(id);
            foreach (string upload in Request.Files)
            {
                
                if (Request.Files[upload].FileName != "")
                    
                {
                    string path = Server.MapPath(@"/App_Data/uploads/" + id + "/");
                    string filename = Path.GetFileName(Request.Files[upload].FileName);
                    Response.Write(path);
             
                    bool check = System.IO.File.Exists(Path.Combine(path, filename));
                    

                    //Check if the filename exists or not, send message and refresh
                    if (check==true)
                    {
                        Session["msg"] = "File with the same name already exists - Choose another file or change the file name";
                        System.Diagnostics.Debug.Write("file exists");
                        return RedirectToAction("UploadFiles");
                    }

                    if (check == false)
                    {
                        Session["msg"] = "Successfull Upload";
                        Request.Files[upload].SaveAs(Path.Combine(path, filename));
                        System.Diagnostics.Debug.Write("Upload success");
                        return RedirectToAction("UploadFiles");
                    }
                }
            }

                     return View("Upload");
        }


Then I am calling the message in my view using:
@Session["msg"];


The code is working for the most part i.e. it will check if the file exists/doesn't correctly and print the correct message to the output. My problem is getting the message to the view. If I manually refresh the page my message gets to the view. So that tells me I am making a mistake with how I am redirecting.

I am quite new to Mvc so I can't identify the problem. Any help would be greatly appreciated.
AnswerRe: trouble sending message to the view from controller Pin
F-ES Sitecore29-May-17 22:47
professionalF-ES Sitecore29-May-17 22:47 
GeneralRe: trouble sending message to the view from controller Pin
Hamiltonian1330-May-17 7:23
Hamiltonian1330-May-17 7:23 
GeneralRe: trouble sending message to the view from controller Pin
F-ES Sitecore30-May-17 22:13
professionalF-ES Sitecore30-May-17 22:13 
AnswerRe: trouble sending message to the view from controller Pin
John C Rayan31-May-17 1:56
professionalJohn C Rayan31-May-17 1:56 
GeneralRe: trouble sending message to the view from controller Pin
Hamiltonian1331-May-17 9:16
Hamiltonian1331-May-17 9:16 
GeneralRe: trouble sending message to the view from controller Pin
John C Rayan31-May-17 22:17
professionalJohn C Rayan31-May-17 22:17 
GeneralRe: trouble sending message to the view from controller Pin
F-ES Sitecore1-Jun-17 0:41
professionalF-ES Sitecore1-Jun-17 0:41 
GeneralRe: trouble sending message to the view from controller Pin
John C Rayan1-Jun-17 22:05
professionalJohn C Rayan1-Jun-17 22:05 
GeneralRe: trouble sending message to the view from controller Pin
Hamiltonian139-Jun-17 6:28
Hamiltonian139-Jun-17 6:28 
GeneralRe: trouble sending message to the view from controller Pin
John C Rayan16-Jun-17 2:48
professionalJohn C Rayan16-Jun-17 2:48 
Questionadd small delete button or image to the options of select Pin
indian14326-May-17 13:51
indian14326-May-17 13:51 
QuestionNeed some help in implementing Partial View Pin
indian14323-May-17 13:44
indian14323-May-17 13:44 
AnswerRe: Need some help in implementing Partial View Pin
jkirkerx24-May-17 12:33
professionaljkirkerx24-May-17 12:33 
GeneralRe: Need some help in implementing Partial View Pin
indian14324-May-17 13:26
indian14324-May-17 13:26 
GeneralRe: Need some help in implementing Partial View Pin
jkirkerx25-May-17 10:08
professionaljkirkerx25-May-17 10:08 
Questioncell_double click even on grid view Pin
Mayank Kumar23-May-17 0:14
Mayank Kumar23-May-17 0:14 
AnswerRe: cell_double click even on grid view Pin
Maciej Los23-May-17 20:19
mveMaciej Los23-May-17 20:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.