我有下面的代码。每当我单击上传按钮时,文件都会提交。如果有错误,则会显示在网格中。但是,当我单击页码时,控制器操作“上传”会被调用,并以页码作为输入。此外,当我单击列名进行排序时,控制器操作“上传”会使用 sort=columnname 和 sortDIR=ASC 参数调用。
我想阻止这些控制器动作调用。
在控制器中:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase fileUpload)
{
}
在设计中:
@using (Html.BeginForm("Upload", "FileUpload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="fileUpload" size="35" id="fileupload"/>
<br />
<br />
<span class="button">
<input type="submit" class="form_button" value="Upload" id="btnUpload" />
</span>
<span class="button">
<input type="reset" id="btnCancel" value="Cancel" name="Cancelbutton" class="form_button" />
</span>
<div id="progressbardiv" style="display:none; font-size:medium;">
<img src="../../Images2/ajax-loader.gif"/>Uploading File...
</div>
<br />
<br />
}
@if (Model.lstError != null)
{
<div id="grid">
@{
var grid = new WebGrid(source: Model.lstError,
canSort: true,
rowsPerPage: 10
);
}
@grid.GetHtml(
tableStyle: "webGrid",
headerStyle: "gridHead",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("RowId", header: "Sr.No"),
grid.Column("EmployeeID", header: "Emp Id"),
grid.Column("ApplicantID", header: "Candidate Id"),
grid.Column("EmployeeName", header: "Employee Name"),
grid.Column("Message", header: "Message")
)
)
</div>
}