前台HTML
<form id="form_measures_entity_detail" style="float:left" method="post" role="form" enctype="multipart/form-data" class="form-container">
<label style="text-align:right">@Label.DataFolder</label>
<input id="measures" class="long" style="height:22px;" name="fbTemplate" type="file" labelPosition="top" prompt='@Label.PleaseSelectFile' buttonText='@Label.PleaseSelectFile' onChange="UploadFile('measures')">
<div hidden="hidden">
<input id="SnType" type="hidden" name="SnType" value="" />
</div>
</form>
<label>
<a id="btn" class="easyui-linkbutton"style="margin-left: 20px; float: left; display: @(Model.InspectResult.Equals(string.Empty)?"block":Model.InspectResult.Equals(Const.FAILED)? "block" : "none")" tabindex="10" data-options="iconCls:'icon-ok'" onclick="doUpload('measures')">@Label.Import</a>
</label>
JS
//文件上传
function UploadFile(newValue) {
if (newValue != "") {
var filePath = $('#' + newValue+'').val();
if (filePath.indexOf(".xlsx") == -1 ) {
var msg = '@Html.Raw(Message.PleaseSelectSnTemplate)';
$.messager.confirm('@Label.Confirm', msg, function () {
var obj = document.getElementById('' + newValue + '');
obj.outerHTML = obj.outerHTML;
});
}
}
}
function doUpload(newValue) {
var filePath = $('#' + newValue+'').val();
if (filePath == '' || filePath == null) {
$.messager.alert('@Label.Warning', '@Message.PleaseSelectTemplateFile', 'warning');
}
else {
//组建 options 传递另外的参数
var options = {
url: "@resourceHost/@Const.WEB_AREA_PRODUCTIONMANAGEMENT/OBA/UploadFile",
data: { InspectId:"@Model.InspectId" , SalesOrder:"@Model.SalesOrder", Prod:"@Model.Prod", Type:newValue},
success: function (message) {
var date = JSON.parse(message);
console.log(date);
$.messager.alert('@Label.Warning', date.message, 'warning');
}
};
if ($('#form_' + newValue + '_entity_detail').form('validate')) {
$('#form_' + newValue + '_entity_detail').ajaxSubmit(options);
}
}
}
注意:form 上传文件 一般不会携带其它参数
方式1、给 input 标签赋值,隐藏,一个参数一个input 不适用
方式2、组建 options 传递另外的参数
//组建 options 传递另外的参数
var options = {
url: "@resourceHost/@Const.WEB_AREA_PRODUCTIONMANAGEMENT/OBA/UploadFile",
data: { InspectId:"@Model.InspectId" , SalesOrder:"@Model.SalesOrder", Prod:"@Model.Prod", Type:newValue},
success: function (message) {
var date = JSON.parse(message);
console.log(date);
$.messager.alert('@Label.Warning', date.message, 'warning');
}
};
if ($('#form_' + newValue + '_entity_detail').form('validate')) {
$('#form_' + newValue + '_entity_detail').ajaxSubmit(options);
}
}
网友评论