File Upload ASP.NET MVC 3.0

后端 未结 21 1355
无人共我
无人共我 2020-11-22 01:09

(Preface: this question is about ASP.NET MVC 3.0 which was released in 2011, it is not about ASP.NET Core 3.0 which was released in 2019)

I want to

21条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 01:39

    Most of the answers seems legit enough although I did a sample project for you on donnetfiddle

    I'm using LumenWorks.Framework for CSV work but its not a must have.

    Demo

    View

                @using (Html.BeginForm("Index", "Home", "POST")) 
    
                {
                    


    Controller:

        [HttpPost]
        public ActionResult Index(HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    // Validation content length 
                    if (upload.FileName.EndsWith(".csv") || upload.FileName.EndsWith(".CSV"))
                    {
                        //extention validation 
                        ViewBag.Result = "Correct File Uploaded";
                    }
                }
            }
    
            return View();
        }
    

提交回复
热议问题