1

I have below piece of code. Whenever I click on upload button, the file submits. If there is an error, then it will be displayed in the grid. But, when I click on A page number, then the controller action, "Upload," gets called with the page number as the input. Also, when I click on the column name for sorting, then the controller action "Upload" gets called with sort=columnname and sortDIR=ASC parameters.

I want to prevent these controller action calls.

In Controller:

[HttpPost]
public ActionResult Upload(HttpPostedFileBase fileUpload)
{
}

In Design:

@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" />&nbsp;&nbsp;                       
    </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> 
}
Jim D'Angelo
  • 3,952
  • 3
  • 25
  • 39
Sameer More
  • 589
  • 1
  • 6
  • 13

1 Answers1

0

Since you are loading the grid from the Upload action, that is where the grid is going to go back to pull the paged data and do sorting. If you see this answer, it explains that there is not a clear way to get around this behavior using the WebGrid, and provides alternative solutions.

Community
  • 1
  • 1
Jim D'Angelo
  • 3,952
  • 3
  • 25
  • 39