c# - ASP.net MVC upload image NullReferenceException -
I have implemented a simplified method for inserting data into the database, and it worked fine I decided to upload the image Done, but I'm getting NullReferenceException (the file is empty) and I can not know why I hope you can help me!
This is my code:
[Authorized] Create public actions () {viewBag.CategoryId = new selection list (_categoryRepository.GetAllCategories () (Asenumerable), "Category ID ", "Name"); See Return (); } // // Post: / advert / create [hppost, author] public action result (contest dto contest dto, html posted filebase file) {if (file.ContentLength & gt; 0) {string fileName = path.get filename (file. FileName); String File Extension = Path Gate extension (filename); If (fileExtension == ".jpg") || (File Extension == ".PNGG")) {string path = Path.Combine (Server.MapPath ("~ / Upload / Images"), Filename); File.SaveAs (Path); CompetitionDTO.ImageURL = Path; }} If (ModelState.ISIIIDID) {_competitionRepository.AddCompetition (Contest DTO, WebSquiry Content Content ID); Return Redirect Action ("Index"); } ViewBag.CompetitionId = New Selection List (_competitionRepository.GetAllCompetitions (). AsEnumerable (), "Contest", "Name"); See Return (Contest DTO); }} See more
& lt; Div & gt; Use as "HTML" ("Create", "Contest", "Contest", FormMethod.Post, New {enctype = "multipart / form-data", id = "ParentForm"}) {{"file" id = "file" /> & Lt; Input type = "submit" value = "create" /> } & Lt; / Div & gt;
And I know how to upload files, and I want to submit when I submit, So get those two things at the same time
It was my fault that I have two HTMLs. Benform, now I mixed them in one and it works fine
Comments
Post a Comment