我有一个表单,我需要上传文件运行时并传递一些数据运行时。我在下面给出我的代码。这是我的 Cshtml。
<div id="SenMailForm" class="divFlotter">
<div class="divHeader">
Send Resume</div>
<div id="BasicJobDescriptionInfo" class="divInner">
<table width="100%">
<tr>
<td width="10%">
To
</td>
<td width="90%">@Html.TextBox("txtTo", "", new { @class = "inputBoxLogin_L", style = "width:800px" })
</td>
</tr>
<tr>
<td>
CC
</td>
<td>@Html.TextBox("txtCC", "", new { @class = "inputBoxLogin_L", style = "width:800px" })
</td>
</tr>
<tr>
<td>
BCC
</td>
<td>@Html.TextBox("txtBCC", "", new { @class = "inputBoxLogin_L", style = "width:800px" })
</td>
</tr>
<tr>
<td>
Subject
</td>
<td>@Html.TextBox("txtSubject", "", new { @class = "inputBoxLogin_L", style = "width:800px" })
</td>
</tr>
<tr>
<td>
Attachment
</td>
<td>
<div id="dvAttachments">
</div>
</td>
</tr>
<tr>
<td>
Other Attachment
</td>
<td>
@using (Html.BeginForm("StoreOtherAttachment", "Vacancy", FormMethod.Post, new { id = "StoreOtherAttachmentForm", enctype = "multipart/form-data" }))
{
<input class="inputBoxLogin_Small" id="UploadResume" type="file" name="UploadResume" style="width: 200px;" />
}
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="checkbox" name="chkSelectAll" value="Bike" checked="checked" onclick="chkSelectAll_Click(this);" />Select
All
<input type="checkbox" name="chkSendResumeInZip" value="Car" />Send Resume(s) in
Zip format Priority
<select id="ddlPriority">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
</select>
</td>
</tr>
</table>
<br />
<table width="100%">
<tr>
<td style="vertical-align: top; width: 10%;">
Body
</td>
<td width="90%">@Html.TextArea("txtEmailBody", "", new { style = "height: 250px; width:100%;", @class = "tinyMCE" })
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right;">
<button id="btnSendEmail" onclick="ActitySendEmail();">
Send</button>
<button id="btnSendEmailClose" onclick="CloseSendEmail();">
Close</button>
</td>
</tr>
</table>
</div>
</div>
下面给出了我的操作方法,下面给出了 Jquery 代码。
public JsonResult StoreOtherAttachment(HttpPostedFileBase
UploadResume)
{
if (UploadResume != null)
{
byte[] tempImage = new byte[UploadResume.ContentLength];
}
return null;
}
public JsonResult ActitySendEmail(string strTo, string strCC)
{
//Doing something
}
function ActitySendEmail() {
var dataString;
var contentType;
var processData;
action = $("#StoreOtherAttachmentForm").attr("action");
if ($("#StoreOtherAttachmentForm").attr("enctype") == "multipart/form-data") {
dataString = new FormData($("StoreOtherAttachmentForm").get(0));
contentType = false;
processData = false;
}
else {
// regular form, do your own thing if you need it
}
$.ajax({
type: "POST",
url: action,
data: dataString,
dataType: "json", //change to your own, else read my note above on enabling the JsonValueProviderFactory in MVC
contentType: contentType,
processData: processData,
success: function (data) {
},
error: function (jqXHR, textStatus, errorThrown) {
//do your own thing
}
});
var strTo1 = $("#txtTo").val();
var strCC1 = $("#txtCC").val();
var strBCC1 = $("#txtBCC").val();
var strSubjrct1 = $("#txtSubject").val();
var strEmailBody1 = tinyMCE.activeEditor.getContent();
var e = document.getElementById("ddlPriority");
var strPriority = e.options[e.selectedIndex].value;
if (strTo1.length > 0) {
$.ajax({
url: "/Vacancy/ActitySendEmail",
data: { strTo: strTo1, strCC: strCC1, strBCC: strBCC1, strSubjrct: strSubjrct1, strEmailBody: strEmailBody1,
strSelectedFiles: strSelectedItemsToSendResume, strPriority:
strPriority },
dataType: "json",
type: "POST",
success: function (data) {
if (true == data) {
$("#txtTo").val(null);
$("#txtCC").val(null);
$("#txtBCC").val(null);
$("#txtSubject").val(null);
tinyMCE.activeEditor.setContent('');
$("#SenMailForm").slideUp();
$.msgBox({
title: "Send Resume",
content: "Resume(s) send successfully.",
type: "info"
});
}
else {
$.msgBox({
title: "Send Resume",
content: "Resume(s) does not send.",
type: "error"
});
}
}
});
}
else {
$.msgBox({
title: "Send Resume",
content: "Please provide TO Email-Id.",
type: "error"
});
} }
我想在 ActitySendEmail 之前执行 StoreOtherAttachment 。这怎么可能?