开发者

How to get alerts from action in asp.net mvc

as far as I know we can not call the javascript method in controller's action method. but how to consider that a particular code line get executed ? As i asked earlier here we must have to get acknowledgment that line number so and so get executed. see this action in my controller

 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult uploadfile(FormCollection fc)
        {
            UserMaster objUMaster = objAM.GetUser(new Guid(fc["userIdForFile"].ToString()));
            try
            {

                string imagename = "";
                //Check for files uploaded here.
                foreach (string inputTagName in Request.Files)
                {

                    HttpPostedFileBase file = Request.Files[inputTagName];
                    imagename = objUMaster.UserId.ToString() + file.FileName;
                    if (file.ContentLength > 0)
                    {
                        string filePath = Path.Combine(HttpContext.Server.MapPath("../Cont开发者_JS百科ent/UserUploads"), objUMaster.UserId.ToString() + Path.GetFileName(file.FileName));
                        file.SaveAs(filePath);

                        string filePathThumb = Path.Combine(HttpContext.Server.MapPath("../Content/UserUploads/Thumbnails"), objUMaster.UserId.ToString() + Path.GetFileName(file.FileName));

                        var fl = Request.Files.Get(inputTagName);
                        Stream strm = fl.InputStream;
                        Image img = Image.FromStream(strm);

                        ResizeAndSaveHighQualityImage(img, 120, 120, filePathThumb, 100);


                    }

                }
                objUMaster.ProfilePhoto = imagename;
                objAM.Save();



                return RedirectToAction("EditProfile", new { id = objUMaster.UserId });
            }
            catch (Exception ex)
            {
                //SendEmail(ex.Message);

                string strPath = HttpContext.Server.MapPath("../Content/UserUploads");

                StreamWriter SW;
                SW = System.IO.File.CreateText(strPath+"/log.txt");
                SW.WriteLine(ex.Message.ToString());             
                SW.Close();

                return RedirectToAction("EditProfile", new { id = objUMaster.UserId });
            }
        }

Here I am trying to upload the image in my domains file system (dir). but I want get alert so that I can confirm , this lie get executed successfully. because nothing happening as expected from this action. so can we call Javascript's "alert", or something else remedy?


Some pointers to help you:

  • See if Network service/account under which your application is running has permission on the location where you are saving your file.

Besides this to make sure that your file is saved, after save call you can make another call File.IsExist. If it exists then you can log the success/failure in some log file. Wouldn't that work for you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜