2017-04-15 24 views
0

使用angular将Html表值发送到mvc控制器操作方法。这是我的角码。如何使用entityframeworkextra将表值分配给存储过程参数

 var feedbackdata = { 

     SpeakerRatings: $scope.SpeakerTable // This scope contains two rows of table data 
    }; 

    FeedBackFormfac.InsertFeedback(feedbackdata).then(function (data) { 
     alert(data.data) 
    }) 

    fac.InsertFeedback = function (d) { 

    return $http({ 
     url: '/Feedback/Insert', 
     method: 'POST', 
     data: JSON.stringify(d), 
     headers: {'content-type': 'application/json'} 
    }); 
}; 

而在我的控制器的操作方法接收该JSON数据IM。即时尝试使用entityframeworkextra将这些数据插入到我的数据库中。但我不能将表值绑定到参数SpeakerRatings。

public JsonResult Insert(FeedBackFormVM F) 
    { 
      var procedure = new InsertFeedbackSP() 
      { 
       SpeakerRatings = new List<SpeakerRatingsUDT> 
       { 
        new SpeakerRatingsUDT() 

       } 
      } 

    } 

在上面的代码中即时试图结合来自角即传来的数据(对象F包含HTML表格的值),以用户定义的其使用entityframeworkextra创建和我的用户定义表的类将是这样

表型类
[UserDefinedTableType("SpeakerRatingsType")] 
public class SpeakerRatingsUDT 
{ 
    [UserDefinedTableTypeColumn(1)] 
    public int SpeakerId { get; set; } 
    [UserDefinedTableTypeColumn(2)] 
    public string SpeakerName { get; set; } 
    [UserDefinedTableTypeColumn(3)] 
    public int Rating { get; set; } 
} 

回答

0

林接收HTML表格的值到与列表类型UserdefinedType类的

public JsonResult Insert(FeedBackFormVM F) 
    { 
      List<SpeakerRatingsVM> newdata = F.SpeakerRatings; 
      var procedure = new InsertFeedbackSP() 
      { 
       SpeakerRatings = newdata.Select(x => new SpeakerRatingsUDT { 
     SpeakerId=x.SpeakerId,SpeakerName=x.SpeakerName,Rating=x.Rating}).ToList() 

      } 

    } 
相关问题