TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
The Gamer
NA
9
1.5k
Converting file to bytes then saving to SQL using C# MVC
Aug 10 2018 10:34 AM
Good morning!
I was able to do this in asp.net but I am moving to MVC using C# and am stuck.
Here is my view:
@
using
(Html.BeginForm())
{
@Html.AntiForgeryToken()
<input type="file" id="bgFileUpload" name="bgFileUpload" />
<input type="submit" id="createNewBtn_id" name=
"submitNew"
value=
"submitNew"
/>
}
and then I have this in my controller:
public
ActionResult Admin(string submitNew)
{
uploadFileToSqlDb();
return
View();
}
The above calls my function. Here is the function:
[HttpPost]
public
ActionResult uploadFileToSqlDb()
{
byte[] uploadedFile =
new
byte[Request.Files[
"bgFileUpload"
].InputStream.Length];
return
View();
}
But everytime I get a "Object reference not set to an instance of an object". Any suggestions for a noobie such as myself?
Everything I have seen online I appear to be doing incorrectly or possibly interpretting it wrong.
Reply
Answers (
2
)
Asynchronous Coding in C#
How to show demo title in Dropdownlist