1

I know this has been asked a lot of times. But believe me I have tried them and this ain't working.

I have this simple List and Method :-

$scope.TblData = [];
        var Name='Name'; var Desc='Desc';
        $scope.TblData = [
            { Key: Name, Value: ClassSubjectName },
            { Key: Desc, Value: ClassSubjectDesc }
        ];
        InsertFactory.InsertClassSubject($scope.TblData).then(function (d) {
            alert(d.data + ' Subject Details');
        }, function (error) {
            alert('Cannot Save Contact Details');
        })

Which I'm getting at factory like :-

    BoardObj.InsertClassSubject = function (TblData) {
    var ViewID = 'ClassSubject';
    var Data = $.param({ TblList: ViewID, TblData: TblData });
    return $http({
        method: 'POST',
        url: '/Admin/InsertTblData',
        data: JSON.stringify(Data),
        headers: {
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
        }
    });
}

Trying to get it at server like this:-

if (Request.Form["TblData"] != null)
        {
            JsonData =  Request.Form["TblData"].ToString();
        }
        aBundleInsert.TblDataParams = JsonConvert.DeserializeObject<List<KeyValuePair<string, string>>>(JsonData);

Ofcourse I'm doing it wrong but can't find the issue.

Deepak
  • 376
  • 6
  • 23

1 Answers1

0

You are not posting your data as form post. TblData is a scope variable, it will not come inside your Form object, Form is meant for input elements only.

Ideally you should be posting the data to a model at the server side, but if you still want to access it on server side, you can try like following.

string postContent = "";
HttpContext.Current.Request.InputStream.Position = 0;
using (var reader = new StreamReader(Request.InputStream, 
System.Text.Encoding.UTF8, true, 4096, true))
{
    if (HttpContext.Current.Request.ContentLength > 0)
    {
        postContent = reader.ReadToEnd();
    }
}
PSK
  • 17,547
  • 5
  • 32
  • 43