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?

7
  • Can you show your TblFishCar model class? Also, see this answer - stackoverflow.com/questions/30957248/… Commented Aug 8, 2017 at 8:03
  • yes edited my post Commented Aug 8, 2017 at 8:10
  • Change Guid to string in the model class and remove [FromBody] from the method argument. You could cast the string to guid later in method body(if need be!). Commented Aug 8, 2017 at 8:20
  • i use this link , but GetFishReport doesn't has value. Commented Aug 8, 2017 at 8:25
  • Please update your post as to what change did you make? Also, console.log($scope.TblFishCar) to check if IdFish property has value before post? Commented Aug 8, 2017 at 8:28

1 Answer 1

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

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.