Formdata object is converting into querystring in ASP.NET MVC
I am sending formdata data to an MVC controller, but when I send the request sometimes the formdata is converted into querystring or missing some values.
When I debug my code in Chrome the request is sent to the server but sometimes it will not include cityid and image in the request.
This is my jQuery add function:
function add()
{
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
formdata.append('name', $('#name').val());
formdata.append('lastname', $('#lastname').val());
formdata.append('address', $('#address').val());
formdata.append('imageuploaded', imagefile);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: "/Practice/insertemployee",
type: "Post",
contentType: false,
processData: false,
data: formdata,
success: onsccessinsert,
error:onerrorinsert
});
}
My controller:
public JsonResult insertemployee(People people,HttpPostedFileBase
imageuploaded)
{
var name= imageuploaded.FileName;
var folderpath = Server.MapPath(@"Images");
string guid = new Guid().ToString();
var fullpath = folderpath +guid+ name;
people.fullimagepath = fullpath;
people.shortimagepath=@"Images"+guid+name;
imageuploaded.SaveAs(fullpath);
return Json(PracticedbcontexController.insertintodb(people), JsonRequestBehavior.AllowGet);
}
And finally, the view markup:
<form id="peopleform" enctype="multipart/form-data" >
<div class="form-group">
<input type="hidden" id="id" />
<label>name</label>
<input type="text" class="form-control" id="name" name="name" />
</div>
<div class="form-group">
<label>lastname</label>
<input type="text" class="form-control" id="lastname" name="lastname" />
</div>
<div class="form-group">
<label>address</label>
<input type="text" class="form-control" id="address" name="address" />
</div>
<select id="listofcities" onchange="citiesselected()">
<option value="1">karachi</option>
<option value="2">hyderabad</option>
<option value="3">larkana</option>
</select>
<div class="form-group">
<input type="file" id="imageuploaded" name="imageuploaded" class="form-control" />
</div>
<ul id="cityid"></ul>
<button id="submitform" class="btn btn-primary" onclick="add()">submit</button>
</form>
When I send the request to the server, the request is converted into query string instead of formdata object. When I debug and send the request it appears to be missing some data. I have inspected all the values are attached to formdata.
javascript c# jquery html asp.net-mvc
add a comment |
I am sending formdata data to an MVC controller, but when I send the request sometimes the formdata is converted into querystring or missing some values.
When I debug my code in Chrome the request is sent to the server but sometimes it will not include cityid and image in the request.
This is my jQuery add function:
function add()
{
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
formdata.append('name', $('#name').val());
formdata.append('lastname', $('#lastname').val());
formdata.append('address', $('#address').val());
formdata.append('imageuploaded', imagefile);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: "/Practice/insertemployee",
type: "Post",
contentType: false,
processData: false,
data: formdata,
success: onsccessinsert,
error:onerrorinsert
});
}
My controller:
public JsonResult insertemployee(People people,HttpPostedFileBase
imageuploaded)
{
var name= imageuploaded.FileName;
var folderpath = Server.MapPath(@"Images");
string guid = new Guid().ToString();
var fullpath = folderpath +guid+ name;
people.fullimagepath = fullpath;
people.shortimagepath=@"Images"+guid+name;
imageuploaded.SaveAs(fullpath);
return Json(PracticedbcontexController.insertintodb(people), JsonRequestBehavior.AllowGet);
}
And finally, the view markup:
<form id="peopleform" enctype="multipart/form-data" >
<div class="form-group">
<input type="hidden" id="id" />
<label>name</label>
<input type="text" class="form-control" id="name" name="name" />
</div>
<div class="form-group">
<label>lastname</label>
<input type="text" class="form-control" id="lastname" name="lastname" />
</div>
<div class="form-group">
<label>address</label>
<input type="text" class="form-control" id="address" name="address" />
</div>
<select id="listofcities" onchange="citiesselected()">
<option value="1">karachi</option>
<option value="2">hyderabad</option>
<option value="3">larkana</option>
</select>
<div class="form-group">
<input type="file" id="imageuploaded" name="imageuploaded" class="form-control" />
</div>
<ul id="cityid"></ul>
<button id="submitform" class="btn btn-primary" onclick="add()">submit</button>
</form>
When I send the request to the server, the request is converted into query string instead of formdata object. When I debug and send the request it appears to be missing some data. I have inspected all the values are attached to formdata.
javascript c# jquery html asp.net-mvc
can you also provide your view code
– maximelian1986
Jan 3 at 7:59
@maximelian html code ?
– ahmedshah
Jan 3 at 7:59
c# view code as you using mvc
– maximelian1986
Jan 3 at 8:00
Please paste the request data too.
– Dawid Wekwejt
Jan 3 at 8:21
add a comment |
I am sending formdata data to an MVC controller, but when I send the request sometimes the formdata is converted into querystring or missing some values.
When I debug my code in Chrome the request is sent to the server but sometimes it will not include cityid and image in the request.
This is my jQuery add function:
function add()
{
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
formdata.append('name', $('#name').val());
formdata.append('lastname', $('#lastname').val());
formdata.append('address', $('#address').val());
formdata.append('imageuploaded', imagefile);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: "/Practice/insertemployee",
type: "Post",
contentType: false,
processData: false,
data: formdata,
success: onsccessinsert,
error:onerrorinsert
});
}
My controller:
public JsonResult insertemployee(People people,HttpPostedFileBase
imageuploaded)
{
var name= imageuploaded.FileName;
var folderpath = Server.MapPath(@"Images");
string guid = new Guid().ToString();
var fullpath = folderpath +guid+ name;
people.fullimagepath = fullpath;
people.shortimagepath=@"Images"+guid+name;
imageuploaded.SaveAs(fullpath);
return Json(PracticedbcontexController.insertintodb(people), JsonRequestBehavior.AllowGet);
}
And finally, the view markup:
<form id="peopleform" enctype="multipart/form-data" >
<div class="form-group">
<input type="hidden" id="id" />
<label>name</label>
<input type="text" class="form-control" id="name" name="name" />
</div>
<div class="form-group">
<label>lastname</label>
<input type="text" class="form-control" id="lastname" name="lastname" />
</div>
<div class="form-group">
<label>address</label>
<input type="text" class="form-control" id="address" name="address" />
</div>
<select id="listofcities" onchange="citiesselected()">
<option value="1">karachi</option>
<option value="2">hyderabad</option>
<option value="3">larkana</option>
</select>
<div class="form-group">
<input type="file" id="imageuploaded" name="imageuploaded" class="form-control" />
</div>
<ul id="cityid"></ul>
<button id="submitform" class="btn btn-primary" onclick="add()">submit</button>
</form>
When I send the request to the server, the request is converted into query string instead of formdata object. When I debug and send the request it appears to be missing some data. I have inspected all the values are attached to formdata.
javascript c# jquery html asp.net-mvc
I am sending formdata data to an MVC controller, but when I send the request sometimes the formdata is converted into querystring or missing some values.
When I debug my code in Chrome the request is sent to the server but sometimes it will not include cityid and image in the request.
This is my jQuery add function:
function add()
{
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
formdata.append('name', $('#name').val());
formdata.append('lastname', $('#lastname').val());
formdata.append('address', $('#address').val());
formdata.append('imageuploaded', imagefile);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: "/Practice/insertemployee",
type: "Post",
contentType: false,
processData: false,
data: formdata,
success: onsccessinsert,
error:onerrorinsert
});
}
My controller:
public JsonResult insertemployee(People people,HttpPostedFileBase
imageuploaded)
{
var name= imageuploaded.FileName;
var folderpath = Server.MapPath(@"Images");
string guid = new Guid().ToString();
var fullpath = folderpath +guid+ name;
people.fullimagepath = fullpath;
people.shortimagepath=@"Images"+guid+name;
imageuploaded.SaveAs(fullpath);
return Json(PracticedbcontexController.insertintodb(people), JsonRequestBehavior.AllowGet);
}
And finally, the view markup:
<form id="peopleform" enctype="multipart/form-data" >
<div class="form-group">
<input type="hidden" id="id" />
<label>name</label>
<input type="text" class="form-control" id="name" name="name" />
</div>
<div class="form-group">
<label>lastname</label>
<input type="text" class="form-control" id="lastname" name="lastname" />
</div>
<div class="form-group">
<label>address</label>
<input type="text" class="form-control" id="address" name="address" />
</div>
<select id="listofcities" onchange="citiesselected()">
<option value="1">karachi</option>
<option value="2">hyderabad</option>
<option value="3">larkana</option>
</select>
<div class="form-group">
<input type="file" id="imageuploaded" name="imageuploaded" class="form-control" />
</div>
<ul id="cityid"></ul>
<button id="submitform" class="btn btn-primary" onclick="add()">submit</button>
</form>
When I send the request to the server, the request is converted into query string instead of formdata object. When I debug and send the request it appears to be missing some data. I have inspected all the values are attached to formdata.
javascript c# jquery html asp.net-mvc
javascript c# jquery html asp.net-mvc
edited Jan 3 at 9:08
Ade Stringer
2,3541223
2,3541223
asked Jan 3 at 7:50
ahmedshahahmedshah
85
85
can you also provide your view code
– maximelian1986
Jan 3 at 7:59
@maximelian html code ?
– ahmedshah
Jan 3 at 7:59
c# view code as you using mvc
– maximelian1986
Jan 3 at 8:00
Please paste the request data too.
– Dawid Wekwejt
Jan 3 at 8:21
add a comment |
can you also provide your view code
– maximelian1986
Jan 3 at 7:59
@maximelian html code ?
– ahmedshah
Jan 3 at 7:59
c# view code as you using mvc
– maximelian1986
Jan 3 at 8:00
Please paste the request data too.
– Dawid Wekwejt
Jan 3 at 8:21
can you also provide your view code
– maximelian1986
Jan 3 at 7:59
can you also provide your view code
– maximelian1986
Jan 3 at 7:59
@maximelian html code ?
– ahmedshah
Jan 3 at 7:59
@maximelian html code ?
– ahmedshah
Jan 3 at 7:59
c# view code as you using mvc
– maximelian1986
Jan 3 at 8:00
c# view code as you using mvc
– maximelian1986
Jan 3 at 8:00
Please paste the request data too.
– Dawid Wekwejt
Jan 3 at 8:21
Please paste the request data too.
– Dawid Wekwejt
Jan 3 at 8:21
add a comment |
2 Answers
2
active
oldest
votes
I have few suggestions: First is that you may want use more generic approach, so you add peopleView.cshtml (where you put your form) and peopleController.cs and peopleViewModel.cs (where you encapsulate your data, now you have People class). Then you just have and it should do the magic. However I not sure about file input part. So as I understood if you using FormData() your controller must take each value as parameter. So either you put each or your values to separate parameter like
public JsonResult insertemployee(string name, string lastname, HttpPostedFileBase
imageuploaded, etc...)
or you encapsulate on javascript side all people related data into people object:
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
var people = {
'name' = $('#name').val(),
'lastname' = $('#lastname').val()
};
formdata.append('people', people);
formdata.append('imageuploaded', imagefile);
By the way you have 'name' and 'lastname' params, rename 'name' to 'firstname' to be more consistent.
Additional:
So my best guess about long get string is that after calling post with some error it tries to return and fill form with get method. That is why after submitting you get back to form and url have all values. You should have controller with two methods/actions (they may have same name but have different method attributes [HttpGet] and [HttpPost]). In post action in case of error you should return View() with your posted model as parameter. I suggest you to look at some MVC tutorials to get better understanding and study good patterns and naming conventions.
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
Answer is modified
– maximelian1986
Jan 3 at 9:09
add a comment |
Maybe this help you:
var url = "/Practice/insertemployee";
var imagefile = $('#imageuploaded')[0].files[0];
var name = $('#name').val();
var lastname = $('#lastname').val();
var address = $('#address').val();
var formdata = new FormData();
formdata.append('name', name);
formdata.append('lastname', lastname);
formdata.append('address', address);
formdata.append('imageuploaded', imagefile, imagefile.name);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: url,
type: "POST",
data: formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: onsccessinsert,
error: onerrorinsert
});
To adding file use this construction:
formdata.append('imageuploaded', imagefile, imagefile.name);
and set mimetype to:
mimeType: "multipart/form-data",
This will help you with missing files.
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
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%2f54018291%2fformdata-object-is-converting-into-querystring-in-asp-net-mvc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have few suggestions: First is that you may want use more generic approach, so you add peopleView.cshtml (where you put your form) and peopleController.cs and peopleViewModel.cs (where you encapsulate your data, now you have People class). Then you just have and it should do the magic. However I not sure about file input part. So as I understood if you using FormData() your controller must take each value as parameter. So either you put each or your values to separate parameter like
public JsonResult insertemployee(string name, string lastname, HttpPostedFileBase
imageuploaded, etc...)
or you encapsulate on javascript side all people related data into people object:
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
var people = {
'name' = $('#name').val(),
'lastname' = $('#lastname').val()
};
formdata.append('people', people);
formdata.append('imageuploaded', imagefile);
By the way you have 'name' and 'lastname' params, rename 'name' to 'firstname' to be more consistent.
Additional:
So my best guess about long get string is that after calling post with some error it tries to return and fill form with get method. That is why after submitting you get back to form and url have all values. You should have controller with two methods/actions (they may have same name but have different method attributes [HttpGet] and [HttpPost]). In post action in case of error you should return View() with your posted model as parameter. I suggest you to look at some MVC tutorials to get better understanding and study good patterns and naming conventions.
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
Answer is modified
– maximelian1986
Jan 3 at 9:09
add a comment |
I have few suggestions: First is that you may want use more generic approach, so you add peopleView.cshtml (where you put your form) and peopleController.cs and peopleViewModel.cs (where you encapsulate your data, now you have People class). Then you just have and it should do the magic. However I not sure about file input part. So as I understood if you using FormData() your controller must take each value as parameter. So either you put each or your values to separate parameter like
public JsonResult insertemployee(string name, string lastname, HttpPostedFileBase
imageuploaded, etc...)
or you encapsulate on javascript side all people related data into people object:
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
var people = {
'name' = $('#name').val(),
'lastname' = $('#lastname').val()
};
formdata.append('people', people);
formdata.append('imageuploaded', imagefile);
By the way you have 'name' and 'lastname' params, rename 'name' to 'firstname' to be more consistent.
Additional:
So my best guess about long get string is that after calling post with some error it tries to return and fill form with get method. That is why after submitting you get back to form and url have all values. You should have controller with two methods/actions (they may have same name but have different method attributes [HttpGet] and [HttpPost]). In post action in case of error you should return View() with your posted model as parameter. I suggest you to look at some MVC tutorials to get better understanding and study good patterns and naming conventions.
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
Answer is modified
– maximelian1986
Jan 3 at 9:09
add a comment |
I have few suggestions: First is that you may want use more generic approach, so you add peopleView.cshtml (where you put your form) and peopleController.cs and peopleViewModel.cs (where you encapsulate your data, now you have People class). Then you just have and it should do the magic. However I not sure about file input part. So as I understood if you using FormData() your controller must take each value as parameter. So either you put each or your values to separate parameter like
public JsonResult insertemployee(string name, string lastname, HttpPostedFileBase
imageuploaded, etc...)
or you encapsulate on javascript side all people related data into people object:
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
var people = {
'name' = $('#name').val(),
'lastname' = $('#lastname').val()
};
formdata.append('people', people);
formdata.append('imageuploaded', imagefile);
By the way you have 'name' and 'lastname' params, rename 'name' to 'firstname' to be more consistent.
Additional:
So my best guess about long get string is that after calling post with some error it tries to return and fill form with get method. That is why after submitting you get back to form and url have all values. You should have controller with two methods/actions (they may have same name but have different method attributes [HttpGet] and [HttpPost]). In post action in case of error you should return View() with your posted model as parameter. I suggest you to look at some MVC tutorials to get better understanding and study good patterns and naming conventions.
I have few suggestions: First is that you may want use more generic approach, so you add peopleView.cshtml (where you put your form) and peopleController.cs and peopleViewModel.cs (where you encapsulate your data, now you have People class). Then you just have and it should do the magic. However I not sure about file input part. So as I understood if you using FormData() your controller must take each value as parameter. So either you put each or your values to separate parameter like
public JsonResult insertemployee(string name, string lastname, HttpPostedFileBase
imageuploaded, etc...)
or you encapsulate on javascript side all people related data into people object:
var formdata = new FormData();
var imagefile = $('#imageuploaded')[0].files[0];
var people = {
'name' = $('#name').val(),
'lastname' = $('#lastname').val()
};
formdata.append('people', people);
formdata.append('imageuploaded', imagefile);
By the way you have 'name' and 'lastname' params, rename 'name' to 'firstname' to be more consistent.
Additional:
So my best guess about long get string is that after calling post with some error it tries to return and fill form with get method. That is why after submitting you get back to form and url have all values. You should have controller with two methods/actions (they may have same name but have different method attributes [HttpGet] and [HttpPost]). In post action in case of error you should return View() with your posted model as parameter. I suggest you to look at some MVC tutorials to get better understanding and study good patterns and naming conventions.
edited Jan 3 at 9:08
answered Jan 3 at 8:22
maximelian1986maximelian1986
907519
907519
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
Answer is modified
– maximelian1986
Jan 3 at 9:09
add a comment |
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
Answer is modified
– maximelian1986
Jan 3 at 9:09
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
but why its converting my fromdata into querystring after insert like that /practice?name=qqqqq&lastname=s&address=w&imageuploaded=block.PNG
– ahmedshah
Jan 3 at 8:57
Answer is modified
– maximelian1986
Jan 3 at 9:09
Answer is modified
– maximelian1986
Jan 3 at 9:09
add a comment |
Maybe this help you:
var url = "/Practice/insertemployee";
var imagefile = $('#imageuploaded')[0].files[0];
var name = $('#name').val();
var lastname = $('#lastname').val();
var address = $('#address').val();
var formdata = new FormData();
formdata.append('name', name);
formdata.append('lastname', lastname);
formdata.append('address', address);
formdata.append('imageuploaded', imagefile, imagefile.name);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: url,
type: "POST",
data: formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: onsccessinsert,
error: onerrorinsert
});
To adding file use this construction:
formdata.append('imageuploaded', imagefile, imagefile.name);
and set mimetype to:
mimeType: "multipart/form-data",
This will help you with missing files.
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
add a comment |
Maybe this help you:
var url = "/Practice/insertemployee";
var imagefile = $('#imageuploaded')[0].files[0];
var name = $('#name').val();
var lastname = $('#lastname').val();
var address = $('#address').val();
var formdata = new FormData();
formdata.append('name', name);
formdata.append('lastname', lastname);
formdata.append('address', address);
formdata.append('imageuploaded', imagefile, imagefile.name);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: url,
type: "POST",
data: formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: onsccessinsert,
error: onerrorinsert
});
To adding file use this construction:
formdata.append('imageuploaded', imagefile, imagefile.name);
and set mimetype to:
mimeType: "multipart/form-data",
This will help you with missing files.
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
add a comment |
Maybe this help you:
var url = "/Practice/insertemployee";
var imagefile = $('#imageuploaded')[0].files[0];
var name = $('#name').val();
var lastname = $('#lastname').val();
var address = $('#address').val();
var formdata = new FormData();
formdata.append('name', name);
formdata.append('lastname', lastname);
formdata.append('address', address);
formdata.append('imageuploaded', imagefile, imagefile.name);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: url,
type: "POST",
data: formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: onsccessinsert,
error: onerrorinsert
});
To adding file use this construction:
formdata.append('imageuploaded', imagefile, imagefile.name);
and set mimetype to:
mimeType: "multipart/form-data",
This will help you with missing files.
Maybe this help you:
var url = "/Practice/insertemployee";
var imagefile = $('#imageuploaded')[0].files[0];
var name = $('#name').val();
var lastname = $('#lastname').val();
var address = $('#address').val();
var formdata = new FormData();
formdata.append('name', name);
formdata.append('lastname', lastname);
formdata.append('address', address);
formdata.append('imageuploaded', imagefile, imagefile.name);
for (var i = 0; i < formvalues.cityid.length; i++)
{
formdata.append('cityid['+i+']', formvalues.cityid[i]);
}
$.ajax({
url: url,
type: "POST",
data: formData,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: onsccessinsert,
error: onerrorinsert
});
To adding file use this construction:
formdata.append('imageuploaded', imagefile, imagefile.name);
and set mimetype to:
mimeType: "multipart/form-data",
This will help you with missing files.
edited Jan 3 at 8:22
answered Jan 3 at 8:10
Dawid WekwejtDawid Wekwejt
15510
15510
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
add a comment |
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
Can you perhaps elaborate why this would help?
– zuckerburg
Jan 3 at 8:12
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
@zuckerburg I was editing my answer when You downvote it...
– Dawid Wekwejt
Jan 3 at 8:15
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
yes, but WHY does it help him. You're just giving an answer and telling him what to do. But you're not explaining what was wrong? downvote will stand
– zuckerburg
Jan 3 at 8:17
add a comment |
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%2f54018291%2fformdata-object-is-converting-into-querystring-in-asp-net-mvc%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 also provide your view code
– maximelian1986
Jan 3 at 7:59
@maximelian html code ?
– ahmedshah
Jan 3 at 7:59
c# view code as you using mvc
– maximelian1986
Jan 3 at 8:00
Please paste the request data too.
– Dawid Wekwejt
Jan 3 at 8:21