简体   繁体   中英

how to pass parameter as a object using angularjs mvc c#?

i want to pass pass value as a object using angularjs with ajax call.i have create one class in c#.and now i am call service in angularjs and pass object but controller side i am not getting this value.

i have create this class in c#:

 public class FType
 {
    public string Type { get; set; }
    public string Way { get; set; }
 }

i have write this code for call controller.js :

var Params = {
        Type: 'All',           
        Way: ''
    };
$scope.dtOptions = Userservice.GetAllUserss(DTOptionsBuilder, Params)

this is my service.js code:

this.GetAllUserss = function (DTOptionsBuilder, Params) {        
    var response = DTOptionsBuilder.newOptions().withOption("ajax", {
        dataSrc: "data",
        url: "/admin/getuserlist",
        type: "POST",
        data: Params            
    });
    return response;
};

this is my c# method:

[HttpPost]
    [Route("getuserlist")]
    [AllowAnonymous]
    public ActionResult getuserlist(FType T) // here i am always getting null
    {
    }

any one how can getting this value from c# side please let me know.

    this.GetAllUserss = function (DTOptionsBuilder, Params) {        
    var response = DTOptionsBuilder.newOptions().withOption("ajax", {
        dataSrc: "data",
        url: "/admin/getuserlist?T=",
        type: "POST",
        data: JSON.Stringify(Params)            
    });
    return response;
};

public ActionResult getuserlist(string T)
{

}

Try this you must be getting the data in the service, then deserialize it to the object.

You need to stringify the data to a json string, the MVC default json serializer will take care of the rest

Try it like this:

this.GetAllUserss = function (DTOptionsBuilder, Params) {        
    var response = DTOptionsBuilder.newOptions().withOption("ajax", {
        dataSrc: "data",
        url: "/admin/getuserlist",
        type: "POST",
        data: JSON.Stringify(Params) 
    });
    return response;
};

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