0

I have two projects Asp.net Core and Asp.net Mvc. I wand to send data from the first project(Asp.net Core) to the second project(Asp.net Mvc) with angualrjs

When i run two projects ,my problem is that when I want to post Model from Asp.net Core to ActionResult in Asp.net Mvc , this ActionResult doesn't have value.

Angularjs in first project(Asp.net Core):

$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 in second projcet(Asp.net Mvc):

public class ReportController : Controller
{

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

angularjs calls public ActionResult GetFishReport([FromBody]TblFishCar model) but model doesn't has value.

TblFishCar:

 public partial class TblFishCar
{
    public Guid IdFish { get; set; }
    public int ShFish { get; set; }
    public string DateFish { get; set; }
}

How can i solve this problem?

Mohammad Daliri
  • 1,370
  • 6
  • 20
  • 43

1 Answers1

1

Look at the developer tools of the browser to see the real errors. Also you should enable cross origin requests in your MVC app:

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="*" />
        <add name="Access-Control-Allow-Credentials" value="true" />
      </customHeaders>
    </httpProtocol>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <!--<remove name="OPTIONSVerbHandler" />-->
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
VahidN
  • 18,457
  • 8
  • 73
  • 117