httppostedfilebase

Why IEnumerable<HttpPostedFileBase> count is 1 when I upload 0 files?

删除回忆录丶 提交于 2019-12-10 11:45:40
问题 I have a multiple upload form and I want to check if there is any files when I launch the upload. Here is my code. View : @using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data"})) { <input name="files" type="file" multiple="multiple" /> <input type="submit" value="Upload" /> } Controller : [HttpPost] public ActionResult Upload(IEnumerable<HttpPostedFileBase> files) { if (files.Count() > 0) Console.WriteLine(files.Count()); // display 1 if(files.Any())

MVC - Don't save null image data if image was not re-uploaded in HTTP post (from SportsStore example)

可紊 提交于 2019-12-06 12:34:29
I have been following the SportsStore example project in Apress Pro ASP.NET MVC 3 Framework book and trying to apply the concepts to my application. One area that is bugging me is that in the sample, I can add an image to a product and it gets saved to the database, but if I edit any given product, without uploading a new image for it, the image data is cleared out. I want to be able to edit a product, but if the image data returned from the HTTP post is null, that I want Entity Framework to keep the exisiting image data (and content type). How can I command EF to not update this image field

Save and delete Excel file saved using HttpPostedFileBase

流过昼夜 提交于 2019-12-05 20:14:27
I am uploading an Excel file and extracting data from that and saving it into a database. I am using MVC4 .NET Framework. This is my code from class: public static void Upload(HttpPostedFileBase File) { NIKEntities1 obj = new NIKEntities1(); MyApp = new Excel.Application(); MyApp.Visible = false; string extension = System.IO.Path.GetExtension(File.FileName); string pic = "Excel" + extension; string path = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Excel"), pic); File.SaveAs(path); MyBook = MyApp.Workbooks.Open(path); MySheet = (Excel.Worksheet)MyBook.Sheets[1]; //

MVC3 How to check if HttpPostedFileBase is an image

若如初见. 提交于 2019-12-02 17:35:22
I have a controller like this: public ActionResult Upload (int id, HttpPostedFileBase uploadFile) { .... } How can I make sure that uploadFile is an image (jpg, png etc.) I have tried with using (var bitmapImage = new Bitmap (uploadFile.InputStream)) {..} which throws an ArgumentException if bitmapImage can not be created. Is there a better way for example by looking at uploadFile.FileName? You can check the HttpPostedFileBase object's properties for this ContentType FileName (check the file extensions, which you already know about :) ) Also here is a small method, I have prepared which you

HTTPPostedFileBase always return null in controller

强颜欢笑 提交于 2019-12-02 17:23:22
问题 I have checked various answer for this, but none of them works for me, my code in .cshtml is as follows: <input type="file" name="PostedNRLFile" /> and then in controller I have public JsonResult SaveRecord(NewAuditLetterViewModel viewModel, FormCollection all, string hvalue, HttpPostedFileBase PostedNRLFile) Which is always null, Please help me in this. I have already tried few things like creating a property in viewmodel, this is also null. Also used new { enctype = "multipart/form-data",

HTTPPostedFileBase always return null in controller

南笙酒味 提交于 2019-12-02 10:12:16
I have checked various answer for this, but none of them works for me, my code in .cshtml is as follows: <input type="file" name="PostedNRLFile" /> and then in controller I have public JsonResult SaveRecord(NewAuditLetterViewModel viewModel, FormCollection all, string hvalue, HttpPostedFileBase PostedNRLFile) Which is always null, Please help me in this. I have already tried few things like creating a property in viewmodel, this is also null. Also used new { enctype = "multipart/form-data", id = "documentForm" } in my beginform tag. Also checked their is only one tag in source. You have to add

Upload Image MVC always null

落花浮王杯 提交于 2019-12-02 06:26:15
Hi everyone i am trying to upload a simple image but the HttpPostedFileBase is always remaining null. This is my code i dont know what i am doing wrong. This is my code in the design view: <fieldset> <legend>PictureModel</legend> <div class="editor-label"> <%: Html.LabelFor(model => model.PrivacyTypeID) %> </div> <div class="editor-field"> <%: Html.DropDownList("PrivacyTypeID", null, new { name = "PrivacyTypeID", title = "Please select privacy type.", id = "PrivacyTypeID" }) %> <%: Html.ValidationMessageFor(model => model.PrivacyTypeID) %> </div> <div class="editor-label"> <%: Html.LabelFor

asp.net mvc-5 HttpPostedFileBase is null [duplicate]

独自空忆成欢 提交于 2019-12-01 12:48:38
问题 This question already has answers here : HttpPostedFileBase always return null in ASP.NET MVC (5 answers) Closed 2 years ago . i am messing around with file uploading using asp.net mvc-5 HttpPostedFileBase but it is showing me HttpPostedFileBase is null after i am selecting the image here is my code <input type="file" title="search image" file-model="profileimage" id="allfilepath" name="file" /> <button type="submit" class="btn btn-primary col-sm-5"> <span class="glyphicon glyphicon-plus"><

ASP MVC FIle Upload HttpPostedFileBase is Null

耗尽温柔 提交于 2019-11-30 08:03:44
问题 In my controller I have, because I wanted to be able to fill out some details about the video and actually upload it, the Video class doesn't need the actual video because it's going to be passed to another web service. public class VideoUploadModel { public HttpPostedFileBase vid { get; set; } public Video videoModel { get; set; } } // // POST: /Video/Create [HttpPost] public ActionResult Create(VideoUploadModel VM) { if (ModelState.IsValid) { db.Videos.AddObject(VM.videoModel); db

ASP MVC FIle Upload HttpPostedFileBase is Null

梦想与她 提交于 2019-11-29 06:01:30
In my controller I have, because I wanted to be able to fill out some details about the video and actually upload it, the Video class doesn't need the actual video because it's going to be passed to another web service. public class VideoUploadModel { public HttpPostedFileBase vid { get; set; } public Video videoModel { get; set; } } // // POST: /Video/Create [HttpPost] public ActionResult Create(VideoUploadModel VM) { if (ModelState.IsValid) { db.Videos.AddObject(VM.videoModel); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.UserId = new SelectList(db.DBUsers, "Id", "FName", VM