Как отправить входной текст и FileUploud с помощью Ajax в asp.net C # (веб-формы)?
<input type="text" id="txtChanelName" class="input-field" runat="server" />
<input type="file" id="fpImage" class="input-field" runat="server" />
<button id="btnInsertChanel" onclick="return AddChanel(this.value);"
value='<%=Session["GroupId"].ToString()%>' >add</button>
И мой код JavaScript, как показано ниже
<script>
function AddChanel(groupId) {
var chanelname = document.getElementById("txtChanelName");
var file = document.getElementById("fpImage").files[0];
$.ajax({
type: "POST",
url: "../../Ajax/Chanel.aspx/AddChanel",
data: "{'chanName':'" + chanelname.Value
+ "','groupId':'" + groupId
+ "','image':'" + file + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
//
},
error: function (ex) {
alert("err");
}
});
}
</script>
И мой код C #, как показано ниже
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static bool AddChanel(string chanName,string groupId, string[] image)
{
//Breakpoint
return true;
}