ie中的文件上传帮助问题 [英] file upload helper problem in ie
问题描述
@using Microsoft.Web.Helpers;
@{
Page.Title = "orderReg";
if(!WebSecurity.IsAuthenticated)
{
//navigate to login page
Response.Redirect(App.PathUserLogin + "?returnUrl=" + Request.Url.LocalPath);
}
// Initialize page
var FirstName = string.Empty;
var LastName = string.Empty;
int Gender = 1;
int LangSelect = 1;
var Field = string.Empty;
var Subject = string.Empty;
bool FileValidator = true;
var Description = string.Empty;
List<string> lstFilePaths = new List<string>();
Validation.RequireField("txtField", "specify ...");
Validation.RequireField("txtSubject", "specify ...");
// If this is a POST request, validate and process data
if (IsPost && Validation.IsValid())
{
var db = Database.Open("Trans");
//fetch User Details
var UserProfileRow = db.QuerySingle("SELECT * FROM UserProfile WHERE Id = " + WebSecurity.CurrentUserId);
Gender = Convert.ToInt32(UserProfileRow.Gender);
FirstName = UserProfileRow.FirstName;
LastName = UserProfileRow.LastName;
LangSelect = Convert.ToInt32(Request.Form["LangSelect"]);
Field = Request.Form["txtField"];
Subject = Request.Form["txtSubject"];
Description = Request.Form["txtDescription"];
//validate file(s)
lstFilePaths.Clear();
for(int i = 0; i < Request.Files.Count; i++)
{
if(Request.Files[i].ContentLength == 0)
{
FileValidator = false;
break;
}
else
{
lstFilePaths.Add(Request.Files[i].FileName);
}
}
if(FileValidator == true)
{
//update db
int AuditNum = 1000;
if(db.QueryValue("SELECT COUNT(*) FROM OrderStatus") > 0)
{
AuditNum = db.QueryValue("SELECT MAX(AuditNum) FROM OrderStatus") + 1;
}
string ConcatFileNames = AuditNum.ToString() + "_";
//upload file
for(int i = 0; i < Request.Files.Count; i++)
{
var uploadedFile = Request.Files[i];
var fileName = Path.GetFileName(uploadedFile.FileName);
var SavedFileName = AuditNum.ToString() + "_" + fileName;
var DirectorySavePath = Server.MapPath("~/App_Data/UploadedFiles/" + AuditNum + "/In/");
var fileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" + AuditNum + "/In/" + SavedFileName);// + FileExt);
Directory.CreateDirectory(DirectorySavePath);
uploadedFile.SaveAs(fileSavePath);
var ShortFileName = string.Empty;
if(fileName.Length > 6)
{
ShortFileName = fileName.Substring(0,6);
}
else
{
ShortFileName = fileName;
}
ConcatFileNames += ShortFileName + "_";
}
//insert order status information
db.Execute(@"
INSERT INTO OrderStatus
(AuditNum, Price, Status, PricingTime, WordsNum, DeliveryTime)
VALUES (@0, @1, @2, @3, @4 , @5)",
AuditNum, null, App.strUnVisited, null, null, null);
db.Execute(@"
INSERT INTO OrderDetails
(FileName, Lang, Description, Time, UserId, Subject, Field, AuditNum)
VALUES (@0, @1, @2, @3, @4, @5, @6, @7)",
ConcatFileNames, LangSelect, Description, DateTime.Now, WebSecurity.CurrentUserId, Subject, Field, AuditNum );
db.Close();
db.Dispose();
Session["Description"] = Description;
Session["lstFilePaths"] = lstFilePaths;
string SendingParams = "AuditNum=" + AuditNum + "&FirstName=" + FirstName + "&LastName=" + LastName
+ "&Gender=" + Gender + "&LangSelect=" + LangSelect + "&Field=" + Field + "&Subject=" + Subject;
Response.Redirect("~/Orders/OrderConf?" + SendingParams);
}
}
}
@if(IsPost && !Validation.IsValid() )
{
<div id ="ErrorBorder">
<p>correvt...</p> <br/>
@Html.ValidationSummary()
</div>
}
<form method="post" action="" enctype="multipart/form-data">
<fieldset>
<legend>سفارش ترجمه</legend>
<table class="InTheForm">
<!--<caption>سفارش</caption>-->
<tr>
<th rowspan="2">lang</th>
<td>
<input type="radio" name="LangSelect" value="1" @(LangSelect == 1 ? "checked = 'checked'" : "")/>e2p<br/>
</td>
</tr>
<tr>
<td>
<input type="radio" name="LangSelect" value="0" @(LangSelect == 0 ? "checked = 'checked'" : "")/>p2e
</td>
</tr>
<tr>
<th>field</th>
<td>
<input type="text" name="txtField" value="@Field"/>
<span class="Star">*</span>
</td>
<td><div style="font-size: smaller">examples...</div></td>
</tr>
<tr>
<th>subj</th>
<td>
<input type="text" name="txtSubject" value="@Subject"/>
<span class="Star">*</span>
</td>
</tr>
<tr>
<th>files...</th>
<td>
@FileUpload.GetHtml(
initialNumberOfFiles:1,
allowMoreFilesToBeAdded:true,
includeFormTag:true,
uploadText:"Upload") <!--upload button is hidden using CSS-->
@if (IsPost) {
if(FileValidator == true && Validation.IsValid())
{
<span>uploaded</span> <br/>
}
else if (FileValidator == false)
{
<span>error...</span> <br/>
}
}
</td>
</tr>
<tr>
<th>commects</th>
<td><textarea name="txtDescription" rows="5" style="width: 100%"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align: center"><input type="submit" value="send"/></td>
</tr>
</table>
</fieldset>
</form>
I have got a form in my page which contains a file upload helper and a submit button (and some other controls). My page is working fine and the form can be submitted when browsed by firefox or chrome. But in ie when I press the submit button nothing happens (the form is not submitted to the server). What can cause this browser-specific problem?
I have got a form in my page which contains a file upload helper and a submit button (and some other controls). My page is working fine and the form can be submitted when browsed by firefox or chrome. But in ie when I press the submit button nothing happens (the form is not submitted to the server). What can cause this browser-specific problem?
推荐答案
If you set the includeFormTag as true in your FileUpload helper, it makes a new form into the form that you have already created.
Setting the parameter to false has the result of removing the unnecessary <form> tag and, furthermore, lifts the upload button that you hide with CSS.
Maybe this is the reason why IE doesn’’t work properly.
If you set the includeFormTag as true in your FileUpload helper, it makes a new form into the form that you have already created.
Setting the parameter to false has the result of removing the unnecessary <form> tag and, furthermore, lifts the upload button that you hide with CSS.
Maybe this is the reason why IE doesn''t work properly.
这篇关于ie中的文件上传帮助问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!