0

Im currently learning Asp.NET as far i understand multitier is the best to write webapps.

so I have 2 projects 1 for the Web Api(backend) and other for the Views (frontend)

My Web Api is working nice but when it comes to my frontend i got an little issue. How can I fetch the JSON string in my controller and is it really right how i do it?

    <form id="form1" method="get" action="http://mywebsite.com/test" >
    <div class="modal fade" id="login-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="loginmodal-container">
                <h1>Login</h1><br>

                <input type="text" name="Name" placeholder="Username">
                <input type="password" name="Password" placeholder="Password">
                <input type="submit" name="login" class="login loginmodal-submit" value="Login">


                <div class="login-help">
                    by Dominic
                </div>
            </div>
        </div>
    </div>
</form>

when I try to test it I get "Website could not be shown"

user3110458
  • 374
  • 5
  • 17
  • 2
    You need to make a web request from your MVC app to your API app, you can either do this via AJAX on the client or as part of the controller in your MVC app. I'd suggest going via AJAX from the client unless you need to pre-process the response before you serve it. – James Jul 13 '15 at 12:55

2 Answers2

1

http://www.codeproject.com/Articles/611176/Calling-ASP-NET-WebAPI-using-HttpClient

was in my opinion the best way

user3110458
  • 374
  • 5
  • 17
0

The concept of launching Web API is to completely segregate the Views and Controller . Usual way of interacting with API Controller is using Jquery which is easily extendable and since you are doing it from the client script it is incredibly fast

If you mean you want to get the data in your API Controller . Then you need to call that Api Controller Action Method using $.ajax and you need send the data from front end as a parameter .

This is a great resource for you .

Sending JSON object to Web API

Community
  • 1
  • 1