Asp.net core uploading file and storing file url to databaseHow can I get my webapp's base URL in ASP.NET MVC?Getting full URL of action in ASP.NET MVCFile Upload ASP.NET MVC 3.0How to unit test Asp.net MVC fileUploadUnit test controller - membership errorHow do you create a custom AuthorizeAttribute in ASP.NET Core?Read file from model asp.net core 1.1Populate dropdownlist from database in asp.net MVC in a formmodelstate.isvalid false because the item always nullASP.net MVC problem in Controller managing a [HttpPost] : renders Layout and Page twice
Why did IBM make the PC BIOS source code public?
Solving pricing problem heuristically in column generation algorithm for VRP
When was "Fredo" an insult to Italian-Americans?
Setting up a Mathematical Institute of Refereeing?
If a person claims to know anything could it be disproven by saying 'prove that we are not in a simulation'?
Sums of binomial coefficients weighted by incomplete gamma
Solving a maximum minimum problem
What modifiers are added to the attack and damage rolls of this unique longbow from Waterdeep: Dragon Heist?
What's the relationship betweeen MS-DOS and XENIX?
Heyawake: An Introductory Puzzle
What's the point of writing that I know will never be used or read?
How to programatically get all linked items for a given Sitecore item?
Unconventional examples of mathematical modelling
What can I do to increase the amount of LEDs I can power with a pro micro?
Would the USA be eligible to join the European Union?
Scam? Phone call from "Department of Social Security" asking me to call back
How do figure out how powerful I am, when my abilities far exceed my knowledge?
Perpendicular symbol with litle square
Bringing Power Supplies on Plane?
Airline power sockets shut down when I plug my computer in. How can I avoid that?
How can I shoot a bow using Strength instead of Dexterity?
Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?
Why aren’t there water shutoff valves for each room?
Did Michelle Obama have a staff of 23; and Melania have a staff of 4?
Asp.net core uploading file and storing file url to database
How can I get my webapp's base URL in ASP.NET MVC?Getting full URL of action in ASP.NET MVCFile Upload ASP.NET MVC 3.0How to unit test Asp.net MVC fileUploadUnit test controller - membership errorHow do you create a custom AuthorizeAttribute in ASP.NET Core?Read file from model asp.net core 1.1Populate dropdownlist from database in asp.net MVC in a formmodelstate.isvalid false because the item always nullASP.net MVC problem in Controller managing a [HttpPost] : renders Layout and Page twice
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have the code working in a new seperate test project how ever it will not work with my excisting work project. I am trying to upload a file as part of a form, store it in a folder in wwwroot and store the url in a database. I have posted the code below.The program compiles and runs but does not store anything when create button is pressed. any help would be greatly appreciated.
//Model
namespace PostProjectEvaluations.Web.Models
{
public partial class Projects
[Key]
public int ProjectId get; set;
[Required]
[StringLength(300)]
public string Name get; set;
[Required]
[StringLength(50)]
public string Manager get; set;
public string FilePath get; set;
public class ProjectsVM
public string Name get; set;
public IFormFile File get; set;
//Controller
namespace PostProjectEvaluations.Web.Controllers
public class projectsController : Controller
private readonly IApplicationRepository ApplicationRepository;
private readonly PostProjectEvaluationsContext _context;
private IHostingEnvironment mxHostingEnvironment get; set;
private object objproject;
public projectsController(IApplicationRepository applicationRepository,
IHostingEnvironment hostingEnvironment, PostProjectEvaluationsContext context)
mxHostingEnvironment = hostingEnvironment;
ApplicationRepository = applicationRepository;
_context = context;
public IActionResult Index()
ViewBag.dataSource = ApplicationRepository.GetAllProjects().ToList();
var projects = ApplicationRepository.GetAllProjects();
return View(projects);
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index(ProjectsVM projectsVM)
if (projectsVM.File != null)
//upload files to wwwroot
var fileName = Path.GetFileName(projectsVM.File.FileName);
var filePath = Path.Combine(mxHostingEnvironment.WebRootPath, "Uploads", fileName);
using (var fileSteam = new FileStream(filePath, FileMode.Create))
await projectsVM.File.CopyToAsync(fileSteam);
//your logic to save filePath to database, for example
Projects projects = new Projects();
projects.Name = projectsVM.Name;
projects.FilePath = filePath;
_context.Projects.Add(projects);
_context.SaveChanges();
else
return View("Index");
public IActionResult Details(int id)
var project = ApplicationRepository.GetProjects(id);
return View(project);
[HttpGet]
public IActionResult Create()
var project = new Projects();
return View(project);
[HttpPost]
public IActionResult Create(Projects projects)
ApplicationRepository.Create(projects);
return RedirectToAction("Index");
public IActionResult Delete(int id)
var project = ApplicationRepository.GetProjects(id);
ApplicationRepository.Delete(project);
return RedirectToAction("Index");
[HttpGet]
public IActionResult Edit(int id)
var project = ApplicationRepository.GetProjects(id);
//mxApplicationRepository.SaveChangesAsync();
return View(project);
[HttpPost]
public IActionResult Edit(Projects projects)
ApplicationRepository.Edit(projects);
//mxApplicationRepository.SaveChangesAsync();
return RedirectToAction("Index");
//View
<form enctype="multipart/form-data" asp-controller="Projects" asp-action="Create" method="post" class="form-horizontal">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-body">
<h3 class="form-section">Project Info</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Name</label>
<div class="col-md-9">
<input asp-for="Name" class="form-control" placeholder="Name">
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
</div>
<!--/span-->
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Manager</label>
<div class="col-md-9">
<input asp-for="Manager" class="form-control" placeholder="Name">
</div>
</div>
</div>
<!--/span-->
</div>
<!--/span-->
</div>
<h3 class="form-section">Project Files</h3>
<!--/row-->
<div class="row">
<div>
<div class="col-md-6">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<input type="file" name="files" multiple />
</div>
</div>
</div>
<div>
</div>
</div>
<div class="form-actions right">
<input type="submit" class="btn blue-assembly" name="submitButton" value="Save" />
<a asp-action="Index" class="btn default" onclick="cancelClick()">Cancel</a>
</div>
asp.net asp.net-mvc asp.net-core
add a comment |
I have the code working in a new seperate test project how ever it will not work with my excisting work project. I am trying to upload a file as part of a form, store it in a folder in wwwroot and store the url in a database. I have posted the code below.The program compiles and runs but does not store anything when create button is pressed. any help would be greatly appreciated.
//Model
namespace PostProjectEvaluations.Web.Models
{
public partial class Projects
[Key]
public int ProjectId get; set;
[Required]
[StringLength(300)]
public string Name get; set;
[Required]
[StringLength(50)]
public string Manager get; set;
public string FilePath get; set;
public class ProjectsVM
public string Name get; set;
public IFormFile File get; set;
//Controller
namespace PostProjectEvaluations.Web.Controllers
public class projectsController : Controller
private readonly IApplicationRepository ApplicationRepository;
private readonly PostProjectEvaluationsContext _context;
private IHostingEnvironment mxHostingEnvironment get; set;
private object objproject;
public projectsController(IApplicationRepository applicationRepository,
IHostingEnvironment hostingEnvironment, PostProjectEvaluationsContext context)
mxHostingEnvironment = hostingEnvironment;
ApplicationRepository = applicationRepository;
_context = context;
public IActionResult Index()
ViewBag.dataSource = ApplicationRepository.GetAllProjects().ToList();
var projects = ApplicationRepository.GetAllProjects();
return View(projects);
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index(ProjectsVM projectsVM)
if (projectsVM.File != null)
//upload files to wwwroot
var fileName = Path.GetFileName(projectsVM.File.FileName);
var filePath = Path.Combine(mxHostingEnvironment.WebRootPath, "Uploads", fileName);
using (var fileSteam = new FileStream(filePath, FileMode.Create))
await projectsVM.File.CopyToAsync(fileSteam);
//your logic to save filePath to database, for example
Projects projects = new Projects();
projects.Name = projectsVM.Name;
projects.FilePath = filePath;
_context.Projects.Add(projects);
_context.SaveChanges();
else
return View("Index");
public IActionResult Details(int id)
var project = ApplicationRepository.GetProjects(id);
return View(project);
[HttpGet]
public IActionResult Create()
var project = new Projects();
return View(project);
[HttpPost]
public IActionResult Create(Projects projects)
ApplicationRepository.Create(projects);
return RedirectToAction("Index");
public IActionResult Delete(int id)
var project = ApplicationRepository.GetProjects(id);
ApplicationRepository.Delete(project);
return RedirectToAction("Index");
[HttpGet]
public IActionResult Edit(int id)
var project = ApplicationRepository.GetProjects(id);
//mxApplicationRepository.SaveChangesAsync();
return View(project);
[HttpPost]
public IActionResult Edit(Projects projects)
ApplicationRepository.Edit(projects);
//mxApplicationRepository.SaveChangesAsync();
return RedirectToAction("Index");
//View
<form enctype="multipart/form-data" asp-controller="Projects" asp-action="Create" method="post" class="form-horizontal">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-body">
<h3 class="form-section">Project Info</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Name</label>
<div class="col-md-9">
<input asp-for="Name" class="form-control" placeholder="Name">
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
</div>
<!--/span-->
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Manager</label>
<div class="col-md-9">
<input asp-for="Manager" class="form-control" placeholder="Name">
</div>
</div>
</div>
<!--/span-->
</div>
<!--/span-->
</div>
<h3 class="form-section">Project Files</h3>
<!--/row-->
<div class="row">
<div>
<div class="col-md-6">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<input type="file" name="files" multiple />
</div>
</div>
</div>
<div>
</div>
</div>
<div class="form-actions right">
<input type="submit" class="btn blue-assembly" name="submitButton" value="Save" />
<a asp-action="Index" class="btn default" onclick="cancelClick()">Cancel</a>
</div>
asp.net asp.net-mvc asp.net-core
Can you check ifprojectsVM
has a value? i don't think that the model binder is able to bind your input field to this variable because the name on the input field is "files". You could try something likeList<IFormFile> files
as your parameter in the save function
– Elias Johannes
Mar 27 at 12:25
Double check that your file is not null, and I think you'll have to replaceWebRootPath
withContentRootPath
. also check your Debug folder from where your application is ran maybe it's saving the file there.
– Anton Toshik
Mar 27 at 12:35
In debug output i get this error, Cannot insert the value NULL into column 'FilePath', table 'PostProjectEvaluations.dbo.Projects'; column does not allow nulls. INSERT fails.
– Karl Mcgeough
Mar 27 at 13:43
add a comment |
I have the code working in a new seperate test project how ever it will not work with my excisting work project. I am trying to upload a file as part of a form, store it in a folder in wwwroot and store the url in a database. I have posted the code below.The program compiles and runs but does not store anything when create button is pressed. any help would be greatly appreciated.
//Model
namespace PostProjectEvaluations.Web.Models
{
public partial class Projects
[Key]
public int ProjectId get; set;
[Required]
[StringLength(300)]
public string Name get; set;
[Required]
[StringLength(50)]
public string Manager get; set;
public string FilePath get; set;
public class ProjectsVM
public string Name get; set;
public IFormFile File get; set;
//Controller
namespace PostProjectEvaluations.Web.Controllers
public class projectsController : Controller
private readonly IApplicationRepository ApplicationRepository;
private readonly PostProjectEvaluationsContext _context;
private IHostingEnvironment mxHostingEnvironment get; set;
private object objproject;
public projectsController(IApplicationRepository applicationRepository,
IHostingEnvironment hostingEnvironment, PostProjectEvaluationsContext context)
mxHostingEnvironment = hostingEnvironment;
ApplicationRepository = applicationRepository;
_context = context;
public IActionResult Index()
ViewBag.dataSource = ApplicationRepository.GetAllProjects().ToList();
var projects = ApplicationRepository.GetAllProjects();
return View(projects);
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index(ProjectsVM projectsVM)
if (projectsVM.File != null)
//upload files to wwwroot
var fileName = Path.GetFileName(projectsVM.File.FileName);
var filePath = Path.Combine(mxHostingEnvironment.WebRootPath, "Uploads", fileName);
using (var fileSteam = new FileStream(filePath, FileMode.Create))
await projectsVM.File.CopyToAsync(fileSteam);
//your logic to save filePath to database, for example
Projects projects = new Projects();
projects.Name = projectsVM.Name;
projects.FilePath = filePath;
_context.Projects.Add(projects);
_context.SaveChanges();
else
return View("Index");
public IActionResult Details(int id)
var project = ApplicationRepository.GetProjects(id);
return View(project);
[HttpGet]
public IActionResult Create()
var project = new Projects();
return View(project);
[HttpPost]
public IActionResult Create(Projects projects)
ApplicationRepository.Create(projects);
return RedirectToAction("Index");
public IActionResult Delete(int id)
var project = ApplicationRepository.GetProjects(id);
ApplicationRepository.Delete(project);
return RedirectToAction("Index");
[HttpGet]
public IActionResult Edit(int id)
var project = ApplicationRepository.GetProjects(id);
//mxApplicationRepository.SaveChangesAsync();
return View(project);
[HttpPost]
public IActionResult Edit(Projects projects)
ApplicationRepository.Edit(projects);
//mxApplicationRepository.SaveChangesAsync();
return RedirectToAction("Index");
//View
<form enctype="multipart/form-data" asp-controller="Projects" asp-action="Create" method="post" class="form-horizontal">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-body">
<h3 class="form-section">Project Info</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Name</label>
<div class="col-md-9">
<input asp-for="Name" class="form-control" placeholder="Name">
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
</div>
<!--/span-->
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Manager</label>
<div class="col-md-9">
<input asp-for="Manager" class="form-control" placeholder="Name">
</div>
</div>
</div>
<!--/span-->
</div>
<!--/span-->
</div>
<h3 class="form-section">Project Files</h3>
<!--/row-->
<div class="row">
<div>
<div class="col-md-6">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<input type="file" name="files" multiple />
</div>
</div>
</div>
<div>
</div>
</div>
<div class="form-actions right">
<input type="submit" class="btn blue-assembly" name="submitButton" value="Save" />
<a asp-action="Index" class="btn default" onclick="cancelClick()">Cancel</a>
</div>
asp.net asp.net-mvc asp.net-core
I have the code working in a new seperate test project how ever it will not work with my excisting work project. I am trying to upload a file as part of a form, store it in a folder in wwwroot and store the url in a database. I have posted the code below.The program compiles and runs but does not store anything when create button is pressed. any help would be greatly appreciated.
//Model
namespace PostProjectEvaluations.Web.Models
{
public partial class Projects
[Key]
public int ProjectId get; set;
[Required]
[StringLength(300)]
public string Name get; set;
[Required]
[StringLength(50)]
public string Manager get; set;
public string FilePath get; set;
public class ProjectsVM
public string Name get; set;
public IFormFile File get; set;
//Controller
namespace PostProjectEvaluations.Web.Controllers
public class projectsController : Controller
private readonly IApplicationRepository ApplicationRepository;
private readonly PostProjectEvaluationsContext _context;
private IHostingEnvironment mxHostingEnvironment get; set;
private object objproject;
public projectsController(IApplicationRepository applicationRepository,
IHostingEnvironment hostingEnvironment, PostProjectEvaluationsContext context)
mxHostingEnvironment = hostingEnvironment;
ApplicationRepository = applicationRepository;
_context = context;
public IActionResult Index()
ViewBag.dataSource = ApplicationRepository.GetAllProjects().ToList();
var projects = ApplicationRepository.GetAllProjects();
return View(projects);
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index(ProjectsVM projectsVM)
if (projectsVM.File != null)
//upload files to wwwroot
var fileName = Path.GetFileName(projectsVM.File.FileName);
var filePath = Path.Combine(mxHostingEnvironment.WebRootPath, "Uploads", fileName);
using (var fileSteam = new FileStream(filePath, FileMode.Create))
await projectsVM.File.CopyToAsync(fileSteam);
//your logic to save filePath to database, for example
Projects projects = new Projects();
projects.Name = projectsVM.Name;
projects.FilePath = filePath;
_context.Projects.Add(projects);
_context.SaveChanges();
else
return View("Index");
public IActionResult Details(int id)
var project = ApplicationRepository.GetProjects(id);
return View(project);
[HttpGet]
public IActionResult Create()
var project = new Projects();
return View(project);
[HttpPost]
public IActionResult Create(Projects projects)
ApplicationRepository.Create(projects);
return RedirectToAction("Index");
public IActionResult Delete(int id)
var project = ApplicationRepository.GetProjects(id);
ApplicationRepository.Delete(project);
return RedirectToAction("Index");
[HttpGet]
public IActionResult Edit(int id)
var project = ApplicationRepository.GetProjects(id);
//mxApplicationRepository.SaveChangesAsync();
return View(project);
[HttpPost]
public IActionResult Edit(Projects projects)
ApplicationRepository.Edit(projects);
//mxApplicationRepository.SaveChangesAsync();
return RedirectToAction("Index");
//View
<form enctype="multipart/form-data" asp-controller="Projects" asp-action="Create" method="post" class="form-horizontal">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-body">
<h3 class="form-section">Project Info</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Name</label>
<div class="col-md-9">
<input asp-for="Name" class="form-control" placeholder="Name">
<span asp-validation-for="Name" class="text-danger"></span>
</div>
</div>
</div>
<!--/span-->
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3">Project Manager</label>
<div class="col-md-9">
<input asp-for="Manager" class="form-control" placeholder="Name">
</div>
</div>
</div>
<!--/span-->
</div>
<!--/span-->
</div>
<h3 class="form-section">Project Files</h3>
<!--/row-->
<div class="row">
<div>
<div class="col-md-6">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<input type="file" name="files" multiple />
</div>
</div>
</div>
<div>
</div>
</div>
<div class="form-actions right">
<input type="submit" class="btn blue-assembly" name="submitButton" value="Save" />
<a asp-action="Index" class="btn default" onclick="cancelClick()">Cancel</a>
</div>
asp.net asp.net-mvc asp.net-core
asp.net asp.net-mvc asp.net-core
asked Mar 27 at 11:53
Karl McgeoughKarl Mcgeough
112 bronze badges
112 bronze badges
Can you check ifprojectsVM
has a value? i don't think that the model binder is able to bind your input field to this variable because the name on the input field is "files". You could try something likeList<IFormFile> files
as your parameter in the save function
– Elias Johannes
Mar 27 at 12:25
Double check that your file is not null, and I think you'll have to replaceWebRootPath
withContentRootPath
. also check your Debug folder from where your application is ran maybe it's saving the file there.
– Anton Toshik
Mar 27 at 12:35
In debug output i get this error, Cannot insert the value NULL into column 'FilePath', table 'PostProjectEvaluations.dbo.Projects'; column does not allow nulls. INSERT fails.
– Karl Mcgeough
Mar 27 at 13:43
add a comment |
Can you check ifprojectsVM
has a value? i don't think that the model binder is able to bind your input field to this variable because the name on the input field is "files". You could try something likeList<IFormFile> files
as your parameter in the save function
– Elias Johannes
Mar 27 at 12:25
Double check that your file is not null, and I think you'll have to replaceWebRootPath
withContentRootPath
. also check your Debug folder from where your application is ran maybe it's saving the file there.
– Anton Toshik
Mar 27 at 12:35
In debug output i get this error, Cannot insert the value NULL into column 'FilePath', table 'PostProjectEvaluations.dbo.Projects'; column does not allow nulls. INSERT fails.
– Karl Mcgeough
Mar 27 at 13:43
Can you check if
projectsVM
has a value? i don't think that the model binder is able to bind your input field to this variable because the name on the input field is "files". You could try something like List<IFormFile> files
as your parameter in the save function– Elias Johannes
Mar 27 at 12:25
Can you check if
projectsVM
has a value? i don't think that the model binder is able to bind your input field to this variable because the name on the input field is "files". You could try something like List<IFormFile> files
as your parameter in the save function– Elias Johannes
Mar 27 at 12:25
Double check that your file is not null, and I think you'll have to replace
WebRootPath
with ContentRootPath
. also check your Debug folder from where your application is ran maybe it's saving the file there.– Anton Toshik
Mar 27 at 12:35
Double check that your file is not null, and I think you'll have to replace
WebRootPath
with ContentRootPath
. also check your Debug folder from where your application is ran maybe it's saving the file there.– Anton Toshik
Mar 27 at 12:35
In debug output i get this error, Cannot insert the value NULL into column 'FilePath', table 'PostProjectEvaluations.dbo.Projects'; column does not allow nulls. INSERT fails.
– Karl Mcgeough
Mar 27 at 13:43
In debug output i get this error, Cannot insert the value NULL into column 'FilePath', table 'PostProjectEvaluations.dbo.Projects'; column does not allow nulls. INSERT fails.
– Karl Mcgeough
Mar 27 at 13:43
add a comment |
1 Answer
1
active
oldest
votes
Include your model in view as in the first line
@ProjectsVM
You have to give the same name as a model
Try this:
<input type="file" id= name="File" multiple />
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376571%2fasp-net-core-uploading-file-and-storing-file-url-to-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Include your model in view as in the first line
@ProjectsVM
You have to give the same name as a model
Try this:
<input type="file" id= name="File" multiple />
add a comment |
Include your model in view as in the first line
@ProjectsVM
You have to give the same name as a model
Try this:
<input type="file" id= name="File" multiple />
add a comment |
Include your model in view as in the first line
@ProjectsVM
You have to give the same name as a model
Try this:
<input type="file" id= name="File" multiple />
Include your model in view as in the first line
@ProjectsVM
You have to give the same name as a model
Try this:
<input type="file" id= name="File" multiple />
answered Mar 27 at 14:28
Kinjal ParmarKinjal Parmar
2051 silver badge12 bronze badges
2051 silver badge12 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376571%2fasp-net-core-uploading-file-and-storing-file-url-to-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you check if
projectsVM
has a value? i don't think that the model binder is able to bind your input field to this variable because the name on the input field is "files". You could try something likeList<IFormFile> files
as your parameter in the save function– Elias Johannes
Mar 27 at 12:25
Double check that your file is not null, and I think you'll have to replace
WebRootPath
withContentRootPath
. also check your Debug folder from where your application is ran maybe it's saving the file there.– Anton Toshik
Mar 27 at 12:35
In debug output i get this error, Cannot insert the value NULL into column 'FilePath', table 'PostProjectEvaluations.dbo.Projects'; column does not allow nulls. INSERT fails.
– Karl Mcgeough
Mar 27 at 13:43