Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This is my model

public class StudentDataModel
{
    public StudentDataModel();

    [JsonProperty("student_data")]
    public StudentData Data { get; set; }
}



public class StudentData 
{
    public StudentData ();
    [JsonProperty("name")]
    public string Name { get; set; }
    public string Description { get; set; }
    public string Id { get; set; }
    [JsonProperty("active")]
    public bool IsActive { get; set; }

}

In javascript file i have students data like

  $scope.students=[];
$scope.saveStudent=function(){
 return $http.post("/Student/Save?studentData=" + $scope.students)
        .then(function (result) {

        });
};

In students array contains number of students.

Mvc code:-

public async Task<JsonNetResult> Save(List<StudentData> studentData )
    {
       return new JsonNetResult { Data = response };
    }

In the above code i want to pass students array to mvc controller. mvc controller was hitted but data was not passed.

share|improve this question
    
See if this helps: stackoverflow.com/questions/30957248/… – SajalS May 24 '16 at 7:06
    
$http.post("/Student/Save", $scope.students); – Satpal May 24 '16 at 7:13
up vote 2 down vote accepted

Create a request class, and pass those parameters form the UI

$scope.saveStudent=function(){
var inData = {'Students': JSON.stringify($scope.students)};
 return $http.post("/Student/Save?studentData=", inData )
        .then(function (result) {

        });
};

A DTO class for the request:

public class StudentDto
{
  public string Students;
}

Then in the MVC Controller:

public async Task<JsonNetResult> Save(StudentDto request )
{
   var studentList = JsonConvert.DeseralizeObject<>(request.Students).ToList();     
}
share|improve this answer

You should send $scope.students as data i.e. Request content of method $http.post(url, data, [config]);

$http.post("/Student/Save", $scope.students);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.