关于c#:使用angularjs将数据从Asp.net核心发送到Asp.net Mvc

Send data from Asp.net core to Asp.net Mvc with angualrjs

我有两个项目Asp.net CoreAsp.net Mvc
我想用angualrjs

将数据从第一个项目(Asp.net Core)发送到第二个项目(Asp.net Mvc)

当我运行两个项目时,我的问题是,当我想将模型从Asp.net Core发布到Asp.net Mvc中的ActionResult时,该ActionResult没有值。

第一个项目(Asp.net Core)中的Angularjs:

1
2
3
4
5
6
7
8
9
10
11
12
$rootScope.PrintCArd2 = function () {
    $scope.TblFishCar = {};
    $scope.TblFishCar.IdFish = $rootScope.TblFishCarIdFish;


    $http.post("http://localhost:61779/Report/GetFishReport", $scope.TblFishCar).then(function (result) {
        alert("Ok2");
    },
        function (e) {
            alert("warning"+e);
        });
};

第二个项目中的ActionResult(Asp.net Mvc):

1
2
3
4
5
6
7
8
9
10
public class ReportController : Controller
{

    [System.Web.Http.HttpPost]
    public ActionResult GetFishReport([FromBody]TblFishCar model)
    {
        //do something
        return PartialView("_ShowReport");
    }
}

angularjs调用public ActionResult GetFishReport([FromBody]TblFishCar model),但是模型没有价值。

TblFishCar:

1
2
3
4
5
6
 public partial class TblFishCar
{
    public Guid IdFish { get; set; }
    public int ShFish { get; set; }
    public string DateFish { get; set; }
}

我该如何解决这个问题?


查看浏览器的开发人员工具,以查看实际错误。
另外,您还应该在MVC应用中启用cross origin requests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
    <httpProtocol>
      <customHeaders>
       
       
       
      </customHeaders>
    </httpProtocol>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <!--<remove name="OPTIONSVerbHandler" />-->
      <remove name="TRACEVerbHandler" />
     
    </handlers>
  </system.webServer>