简体   繁体   中英

MVC4, C# Declare variable values for once

Im using MVC4, C#.

I have two hidden fields in my Index view. GetData is my another view in which I have implemented infinite scroll, displays data using hidden fields in Index. Whenever the scrollbar is at bottom it reloads the GetData controller, for second time the values in GetData controller are null. Could someone tell me how do I execute a block of code only for once.

Im passing hiddenfields values in Index View

  @Html.BeginForm("GetData", "Home", FormMethod.Post)
  @Html.Hidden("Input1")
  @Html.Hidden("Input2")

GetData Controller

public ActionResult GetData(int? id, string Input1, string Input2)
    {
        int count = 0;
        if (count == 0)
        {
            lat = Convert.ToDecimal(Input1);
            lng = Convert.ToDecimal(Input2);
            count++;
        }
        decimal I1 = Input1;
        decimal I2 = Input2;
     }

Rather than repost to the same action wouldn't it be better to load the new data when you hit the bottom of the scroll using an AJAX request. You could then keep hold of the input values on the client and submit them (to a new action) with the AJAX request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM