Users Pricing

forum

home / developersection / forums / how to use multiple action verb in mvc4

How to use multiple action verb in mvc4

Manish Kumar 2183 22 Mar 2017

How to use multiple action verb in mvc I don’t want to make get action method , I want to use get and post action verb in same action method and how we can know which action verb is called at current time

This is my sample code

Please anyone help me,

      public ActionResult image()
        {
            return View();
        }
       [HttpPost]
        public ActionResult Image(HttpPostedFileBase file)
        {
            if (file != null)
                try
                {
                    // extract only the fielname
                    var fileName = Path.GetFileName(file.FileName);
                    // store the file inside ~/Images folder
                    var path = Path.Combine(Server.MapPath("~/Images/file"), fileName);
                    file.SaveAs(path);                  
                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return View();
         
        }

 

Thank you.

 


Manish Kumar

Other


1 Answers