简体   繁体   English

从JS返回一组值到C#

[英]Returning a set of values from JS to C#

I have a function that returns an element's top and left position, like so 我有一个函数可以返回元素的顶部和左侧位置,就像这样

    $(function GetPos(El) {
      var Offset = $(El).Offset();
      var Top = Offset.Top;
      var Left = Offset.Left;
      return { x: Top, y: Left };
  });

I need to be able to assign and store those values using C# . 我需要能够使用C#分配和存储这些值。 I think Ajax could be the answer, but I don't know how I would set it up. 我认为Ajax可能是答案,但是我不知道如何设置。

I'd like to do something like: 我想做类似的事情:

    Int Top = someAjax[1];

Here is a better example using jQuery - this is probably the easiest way to do it. 这是一个使用jQuery的更好示例-这可能是最简单的方法。

$.ajax({
      type: "POST",
      url: "Default.aspx/DoSomething",
      data: {someParam: "some val"},
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
          //If anything needs to done after ajax call happens
      }
    });

On the server: 在服务器上:

public void DoSomething(string someParam)
{
    //Do whatever you need to
}

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

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