locked
Ajax return data RRS feed

  • Question

  • User-10017267 posted

    I'd like to create a form where the form initially posts the images via Ajax and then after uploaded, the controller returns some data back to the page in the Ajax response. 

    Whats the best way to do this ? 

    Is this the best way or is there some way which is neater ? 

    https://stackoverflow.com/questions/37460852/can-i-return-a-viewbag-property-to-ajax-success-callback

    Saturday, July 6, 2019 11:50 PM

All replies

  • User197322208 posted

    the controller returns some data back to the page in the Ajax response. 

    This is standard Ajax in MVC. Make a controller ( in .NET 4.x , APIController to be fancy) and return ok( with data)

    Sunday, July 7, 2019 2:08 AM
  • User753101303 posted

    Hi,

    As pointed there you can use https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.json?view=aspnet-mvc-5.2 to just return the value you want rather than a view.

    For now it seems you are confusing returning a "raw" value or HTML markup. Or the problem is that you are trying to use a single action while you want to return two distinct things ? Then the simplest approach could be to create another action.

    Monday, July 8, 2019 9:50 AM