如何从 ASP.NET MVC 中的操作获取警报

发布于 2024-10-11 15:54:51 字数 2359 浏览 8 评论 0原文

据我所知,我们无法在控制器的操作方法中调用javascript方法。但如何考虑特定代码行被执行呢?正如我之前问的这里 我们必须得到某行号被执行的确认。在我的控制器中查看此操作

 [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("../Content/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 });
            }
        }

我正在尝试将图像上传到我的域文件系统(目录)中。但我想要得到警报,以便我可以确认,这个谎言已成功执行。因为此操作没有发生预期的情况。那么我们可以称Javascript为“警报”,或者其他补救措施吗?

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("../Content/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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-10-18 15:54:51

一些可以帮助您的提示:

  • 查看运行应用程序的网络服务/帐户是否具有保存文件的位置的权限。

除此之外,为了确保您的文件已保存,在保存调用后您可以再次调用 File.IsExist。如果存在,那么您可以在某个日志文件中记录成功/失败。这对你不起作用吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文