ASP.NET - Como mandar variables de JavaScript a una clase en Asp.Net C#

 
Vista:
Imágen de perfil de efrain

Como mandar variables de JavaScript a una clase en Asp.Net C#

Publicado por efrain (3 intervenciones) el 16/03/2017 18:21:19
Buenas Tardes .
Necesito de su ayuda compañeros, quiero mandar el valor de una variable de javaScript a un Controlador.CS tengo esta funcion.

1
2
3
4
5
6
7
8
function CargarGrabada(id) {
    $("#loading-div-background").show();
    alert(id);
    $.getJSON(uriREST + "/Comisiones/GrabadaDetelles/?Id_Padre=" + id).done(Muestratabla)
     .fail(function (error) { console.log(error); });
    $("#gvgrabadaDetalle").show();
 
}

En la alerta el id me lo manda valor pero al controlador llega 0 Ayuda!!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Enrique
Val: 66
Bronce
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Como mandar variables de JavaScript a una clase en Asp.Net C#

Publicado por Enrique (27 intervenciones) el 03/04/2017 19:43:07
Para rápido puedes levantar un ws que reciba Json y consumirlo con ajax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//code sw
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.Script.Serialization;
 
namespace urNamesSpaces
{
    /// <summary>
    /// Summary description for saveDetail
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class saveDetail : System.Web.Services.WebService
    {
        SanofiCommunityDataContext dba = new SanofiCommunityDataContext();
 
        [WebMethod]
        [ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public string SendQualifed(int id)
        {
            //ur Functions here
 
 
            //Responce ur ws in Json Format
            var json = new JavaScriptSerializer().Serialize(responceMessage);
            return json;
        }
    }
}
 
 
//inHTml
 
 function saveQualif(val) {
        try {
 
            $.ajax({
                type: "POST",
                url: "../../../services/saveDetail.asmx/SendQualifed  ",
                data: "{'id':'"+id+"'}",
                contentType: "application/json; charset=utf-8",
                success: SuccessTestService,
                dataType: "json",
                failure: ajaxCallFailed
            });
        }
        catch (e) {
            alert('failed to call web service. Error: ' + e);
        }
    }
    function SuccessTestService(responce) {
        alert(eval(responce.d));
        LestBack();
    }
    function ajaxCallFailed(error) {
        alert('error: ' + error);
 
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar