0

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.

2
  • See if this helps: stackoverflow.com/questions/30957248/… Commented May 24, 2016 at 7:06
  • $http.post("/Student/Save", $scope.students); Commented May 24, 2016 at 7:13

2 Answers 2

2

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();     
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

$http.post("/Student/Save", $scope.students);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.