0

ASP.NET MVC 4 and C# - I need to know how to avoid a refresh webgrid page when click next page without losing values of textbox (txtMessage). My problem is that when I input values in some Message textbox in a first page and then click the next page and go back to the first page, the values are gone. How to keep values no matter how times you click next page or go back. I have been trying to find solution on Google but I am lost how to solve it.

@{

Layout = "~/Views/Shared/_Layout.cshtml";
var grid = new WebGrid(Model, rowsPerPage: 100, ajaxUpdateContainerId: "gridcontent");
 }

  <div id="gridcontent" >

    @grid.GetWebGrid(
    htmlAttributes: new { id = "grid" },
    tableStyle: "grid",
    headerStyle: "grid-header",
    footerStyle: "grid-footer",
    selectedRowStyle: "rid-selected-row",
    alternatingRowStyle:"grid-alternating-row",
    rowStyle: "grid-row-style",
    mode: WebGridPagerModes.FirstLast | WebGridPagerModes.Numeric | WebGridPagerModes.NextPrevious,
    numericLinksCount: 5,
    firstText: "<< First",
    previousText: "< Previous",
    lastText: "Last >>",
    nextText: "Next >",
    columns: grid.Columns(
                grid.Column(columnName: "AnimalId", header: "Animal ID", style: "colId", format: (item) => string.IsNullOrEmpty(item.AnimalId) ? string.Empty : item.AnimalId),
        grid.Column(columnName: "MessageValue", header: "Message", format: (item) => Html.TextBox("txtMessage", (object)item.MessageValue), canSort: false,),

             grid.Column(header: "View Details", format: @<text><input id="btnView " type="button" value="Details" /></text>),
              ))

  </div>
Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
  • use `ViewData[]` to avoid losing – Praveen S Feb 28 '14 at 11:43
  • really? maybe you can give me a nice example? – user3281338 Feb 28 '14 at 12:00
  • try storing the values of the textbox in session, and populating that textbox from session each time that page is navigated too. The first time a person goes to that page just check if session is null and don't populate, else populate from session – CSharper Feb 28 '14 at 19:48

0 Answers0