getrelax Ответов: 0

В JavaScript сериализация данных изображения, и возвращает значение null, чтобы контроллер MVC


I am trying to save an image to SQL server database using MVC application. With current setting the user can select the image file using imageUpload control and it will be shown in image1 control. For experimental purpose source to image2 control is hardcoded by giving the path to the image file. Then when the user clicks the save button the text data will be saved in the database. However, the serialization of the three controls: imageUpload, image1, and image2 controls returns null to the controller. Due to this I am not able to save the image data. Would you please provide me your suggestion to fix this problem?

Вот код в файле представления
@using (Html.BeginForm("", "EditProfile", FormMethod.Post, new { name= "EditingForm", id = "EditingForm", enctype = "multipart/form-data" }))
{

 <label name="msg" id="msg" style="color:blue"></label>
 @Html.TextBox("Name")
 <input id="imageUpload" name="imageUpload"  type="file"  onchange="DisplayImage(this)" /> //display image will show the selected image on image1 control
  <img id="image1" name="image1"  runat="server"  height="190" width="172" />
  <img id="image2" name="image2"  runat="server" src="~/images/laila.png" height="190" width="172" />
  
  <input type="button" class="btn btn-colored" value="Save Profile" onclick="SaveProfileData('e'); " />
}


Вот код в Javascript
function SaveProfileData(e) {
    var data = $("#EditingForm").serialize();    
    $.post("/Api/Member/SaveMembersData", data, function (result) {
        msg.innerText = result;
        $("#loaderDiv").hide();
    });    
    return false;
};


А вот код в cotroller для того
[HttpPost]
[Route("Api/Member/SaveMembersData")]
public string SaveMembersData(EditMemberRequestModel m)
{

	if (m.Name == null) //this has the proper value
	{
		return "Name can not be empty";
	}
	else
	{
	//....
	}

	if(m.imageUpload != null) //this return null
	{
		//.....
	}

	if(m.image1 != null) //this return null
	{
	//.....
	}

	if (m.image2 != null) //this return null
	{
	//.....
	}
	
	/*
	.....
	*/
	
}


Что я уже пробовал:

Я попытался погуглить некоторые связанные посты, но это мне не помогло.

F-ES Sitecore

Вы не можете сериализовать такой элемент управления загрузкой файлов. google "jquery serialise input file" для альтернативных методов.

getrelax

У вас есть какие-нибудь предложения на этот счет, пожалуйста?

0 Ответов