简体   繁体   English

MVC4,C#一次声明变量值

[英]MVC4, C# Declare variable values for once

Im using MVC4, C#. 我正在使用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. GetData是我实现无限滚动的另一个视图,它使用Index中的隐藏字段显示数据。 Whenever the scrollbar is at bottom it reloads the GetData controller, for second time the values in GetData controller are null. 每当滚动条位于底部时,它都会重新加载GetData控制器,第二次,GetData控制器中的值将为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 GetData控制器

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. 与其重新发布相同的操作,不如当您使用AJAX请求触及滚动的底部时,加载新数据会更好。 You could then keep hold of the input values on the client and submit them (to a new action) with the AJAX request. 然后,您可以保留客户端上的输入值,并使用AJAX请求将其提交(执行新操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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