Using Text Box as the filter for the grid

Feb 27, 2014 at 5:50 PM
Edited Feb 27, 2014 at 5:51 PM
In my application I am want to use Text Box as the filter. When I hit Submit button I will go to the Action Method and gets the Model. And the grid Is built from that model. Problem here is when I hit the paging in the action method I can’t see the text box value as the result I am getting wrong model values.
Below is the code:
Client:
@using (Html.BeginForm("Submit", "ApplicationLog"))
{
<table>
    <tr>
     <td style="font-size:small;width:10%">
        StudentId
    </td>
    <td style="font-size: small;">
        @Html.TextBox( "TransRunId", (string)ViewData["TransRunId"])
    </td> 
    </tr>
    <tr>
       <td style="width: 350px; font-size: small; color: #999999;" align="left">
              <input type="submit" value="Submit"/>

        </td>
    </tr>
</table>
@using GridMvc.Html
@Html.Grid(Model).Columns(columns=>
{
    columns.Add(value=>value.StudentName).Titled("StudentName").SetWidth(100);
    columns.Add(value=>value.DOB).Titled("DOB").SetWidth(100);
}).WithPaging(25)
}

Server side:
public ActionResult Submit(string TransRunId)
   {   
      IList<student_LOG> stdLog = null;  
       CDSDataModel ctx = new CDSDataModel();
       string value = TransRunId;
        stdLog = (from a in ctx.TRAN_LOGs
                  where a.TRAN_LOG_UNIQUE_ID.Contains(value)
                  orderby a.TRAN_LOG_TS descending
                  select a).ToList();
        ViewData["TransRunId"] = value;
       return View("~/Views/StudentLog/Index.cshtml",tranLog);
   }
When I hit paging I am loosing TransRunId value how to retain that value?
Coordinator
Mar 1, 2014 at 5:26 AM
Hi

Try to use you custom filter parameters as query string:
@using (Html.BeginForm("Submit", "ApplicationLog", FormMethod.Get))
{
    <table>
        <tr>
            <td style="font-size:small;width:10%">
                StudentId
            </td>
            <td style="font-size: small;">
                @Html.TextBox("TransRunId", (string)ViewData["TransRunId"])
            </td>
        </tr>
        <tr>
            <td style="width: 350px; font-size: small; color: #999999;" align="left">
                <input type="submit" value="Submit" />
            </td>
        </tr>
    </table>
}