locked
after form submit , need send message from web API to front end to display .How? Thanks. RRS feed

  • Question

  • User-812314942 posted

    <form id="test"  method="post" action="@Url.Content("~load")" >

    <label>Test</label>

    <input name="myfile" type="file" />

    <button type="submit" value="submit" />
    < /form>

    webAPI 

    [Route("~load")] [HttpPost] public async Task<HttpResponseMessage> loadfile() {

    }

    Monday, May 22, 2017 9:09 PM

All replies

  • User-812314942 posted

    <form id="test"  method="post" action="@Url.Content("~load")" >

    <div>

    <label>Test</label>

    <input name="myfile" type="file" />

    <button type="submit" value="submit" />
    < /form>

    webAPI 

    [Route("~load")] [HttpPost] public async Task<HttpResponseMessage> loadfile() {

    return Request.CreateResponse(HttpStatusCode.OK, "Hello");

    }

    even using return Request.CreateResponse(HttpStatusCode.OK, "Hello");

    can not see Hello in front end. Thanks

    Tuesday, May 23, 2017 12:40 AM
  • User-1838255255 posted

    Hi hong_ma,

    According to your description and code, I make a test in my side. As far as I know, the  "@Url.Content" is HomeController. I guess the your API is not under the HomeController.

    So you could make some changes in the code:

    1. change action="@Url.Content("~load")" to action="/load".

    2. change [Route("~load")] to [Route("load")].

    Also you could add a break point in API, make sure it could access the web api.

    if you meet some exception message when you run it, I hope you could post it.

    Best regards,

    Eric Du

    Tuesday, May 23, 2017 9:56 AM