I am developing MVC using APS.NET.
We are developing a system for POST communication using Ajax without using Form.
Since I usually develop mainly in different languages, C # is like an amateur, so I will write the process I want to do below, so I would appreciate it if you could pick it up.

Communication when using Form

  1. User presses a button
  2. POST communication is started and waits for instructions from the server
  3. Redirect based on instructions

I think this is normal processing, but this time I want to do this flow with Ajax.
I will describe the flow in a little more detail.

  1. User press Enter
  2. Detects Enter being pressed in JS
  3. If detected, POST to the specified URL with Ajax
  4. Check validation on server
  5. If the validation is correct, redirect to the specified address
  6. If the validation is incorrect, return the original page
    * At this time, I don't want to do validation because it is troublesome for the client to check it.

I want to do something like this.


Maybe you can't do what I want to do
As the best method, I think that it is most appropriate to include the redirect destination address in the response from the server and perform page transition with JavaScript.

The reason why I want to do this is that when I process it with JS, the value is checked on the browser side and the same thing is done on the server side, so the value is only on the server side like when using Form. I want to build a system that checks and processes in.

Thanks for your guidance.

  • VisualStudio 2019
  • APS.NET MVC v3.1.6
  • Answer # 1

    >If the validation check is NG, stay on the current page and issue an error message.
    >If the validation check is OK, the page will change.
    >Moreover, I want to carry out the validation check on the server side.

    This is the closest image of gpsoft.
    It's a bit exaggerated to not wait for a response in Ajax. Sure, even if you're using a Form, the client will wait for a response from the server and redirect. What I want to do is not check the value on the client, but check the value on the server side and redirect.
    If possible, I don't want to do it because it is annoying to scrutinize the response result on the client and branch the process.

    If that is the case, it seems impossible.

    Even if the server returns a 302 response to the Ajax request, the client does not page transition.
    I think that it is impossible to transition pages with Ajax without the cooperation of the client.