Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to upload a image to the system, but in the view action is not triggering instead of that it is called index() action in the same controller (HOmeController)

In the View :
XML
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BL7HRIS.Models.ImageModal>" %>

<script src="<%: Url.Content("~/Scripts/jquery-1.7.1.min.js") %>"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>"></script>

<% using (Html.BeginForm("Upload","Home", FormMethod.Post))
   { %>
    <%: Html.ValidationSummary(true) %>
        <div>
                    <input name="ImageUploaded" type="file">
                    <input type="submit">
                   <%:ViewBag.path2%>
                    &nbsp;</p>
       </div>
<% } %>

<div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>
<p>
    <img src="Content/Images/Full/<%=ViewBag.path2%>.jpg" alt="No IMAGE UPLOADED" width="304" height="228" /></p>


In the Controller
C#
public ActionResult Index()                     
                    //for image uploader

                      if (fileName != "")
                        {
                            ViewBag.path2 = fileName;
                            fileName = "";
                        }
                        else
                        {

                            ViewBag.path2 = "No IMAGE!";
                        }
                        //return View("Index");                    
                    }

                  //image uploader 

            return View();
        }

// upload method is here

        [HttpPost]
        public ActionResult Upload(ImageModal model)
        {
            if (ModelState.IsValid)
            {
                // string fileName = Guid.NewGuid().ToString();
                string fileName = "A00001";
                fileName = "A00001";
                string serverPath = Server.MapPath("~");
                string imagesPath = serverPath + "Content\\empImages\\";

                string thumbPath = imagesPath + "Thumb\\";
                string fullPath = imagesPath + "Full\\";
                ImageModal.ResizeAndSave(thumbPath, fileName, model.ImageUploaded.InputStream, 80, true);
                ImageModal.ResizeAndSave(fullPath, fileName, model.ImageUploaded.InputStream, 600, true);

anyone have any suggestions? Thanks a lot ? Note this is a partial class and i call this partial class from another view called index :)
            }
            return RedirectToAction("Index");
        }  
        //---------added by heshan for image uploader----//
    }
Posted
v2
Comments
Sergey Alexandrovich Kryukov 11-Feb-13 1:15am    
Partial classes have no effect on functionality, whatsoever, it's just pure syntax.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900