forum

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

How to use multiple action verb in mvc4

Manish Kumar 2057 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.

 


c# mvc4 
Updated on 22-Mar-2017
Manish Kumar

Other


Message
Can you answer this question?

Answer

1 Answers

Liked By