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
Abdullah Nadeem
NA
19
6.6k
Getting image from FormCollection in Controller (MVC)
Aug 15 2018 4:35 PM
Hello everyone from this community! I am a newbie and facing an issue in my application. Please find me a way out. Thanks in anticipation.
I am getting following error while passing image from my form (view) to my controller using FormCollection:
CS0029 : Cannot implicitly convert type 'string' to 'byte[]'
Here's my db class:
(line#52 is creating conflict in my controller)
namespace
KaamAoTemplate.Models
{
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.ComponentModel.DataAnnotations;
public
partial
class
User
{
public
int
UserID {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
FirstName {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
LastName {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
DateofBirth {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
Province {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
City {
get
;
set
; }
public
string
PostalCode {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
CnicNum {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
Contact {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
Email {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
[DataType(DataType.Password)]
public
string
Password {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
[DataType(DataType.Password)]
public
string
ConfirmPassword {
get
;
set
; }
[Compare(
"Password"
)]
[Required(ErrorMessage =
"This field is required!"
)]
public
string
Qualification {
get
;
set
; }
[Required(ErrorMessage =
"This field is required!"
)]
public
string
SkillSet {
get
;
set
; }
public
byte
[] ProfilePicture {
get
;
set
; }
public
decimal
Wallet {
get
;
set
; }
public
Nullable<
byte
> Rating {
get
;
set
; }
public
int
GigCount {
get
;
set
; }
}
}
//here is my controller: (issue in line # 16 and 31 )
[HttpPost]
public
ActionResult Signup(FormCollection form)
{
string
FirstName = form[
"FirstName"
];
string
LastName = form[
"LastName"
];
string
DateofBirth = form[
"DateofBirth"
];
string
Province = form[
"Province"
];
string
City = form[
"City"
];
string
PostalCode = form[
"PostalCode"
];
string
CNIC = form[
"CNIC"
];
string
Contact = form[
"Contact"
];
string
Email = form[
"Email"
];
string
Password = form[
"Password"
];
string
Qualification = form[
"Qualification"
];
string
[] SkillSet = form[
"JobCat"
].Split(
','
);
byte
[] ProfilePicture = form.Get(
"profilepic"
);
User user =
new
User();
user.FirstName = FirstName;
user.LastName = LastName;
user.DateofBirth = DateofBirth;
user.Province = Province;
user.City = City;
user.PostalCode = PostalCode;
user.CnicNum = CNIC;
user.Contact = Contact;
user.Email = Email;
user.Password = Password;
user.Qualification = Qualification;
user.SkillSet = SkillSet.ToString();
user.ProfilePicture = ProfilePicture;
KaamAoDBEntities db =
new
KaamAoDBEntities();
db.Users.Add(user);
db.SaveChanges();
return
View(user);
}
and here's what i have in my view:
for
=
"fileupload"
>Upload Profile Picture
"file"
name=
"profilepic"
value=
""
id=
"fileupload"
>
Reply
Answers (
2
)
Passing table generated from an Entity to the controller
conversion issue