Home>

For example
Suppose the following drop-down menu is written in a file called views/home/index.cshtml. (Razor is not used)

<select class = "title_list" name = 'Title'>
<option value = 'title_select>Please select a title</option>
<option value = "movie_title">is a movie</option>
<option value = "drama_title">Drama.</option>


For example, if I want to display a movie screen (information) without transition when you select a movie, or display a drama screen (information) when you select a drama, how do you use ajax? Is that okay?
I've been investigating a lot, but there are few combinations of ajax and .netMVC.
What I don't know personally
-Should you prepare two view files for each movie and drama?
・ How to switch view file with jQuery = ajax (I don't know which method to use or how to specify the path)

Even if it is not detailed code, it may be in the order of writing such as implementation policy (create two view files → write get method in js file). Thank you.

  • Answer # 1

    Ajax is a mechanism that enables asynchronous communication with the server.
    Even with Ajax, normal server-side processing may not change.
    "Request" and "Response".
    In server-side processing, POST transmission from the client side is received as a "request", and some result is returned as a "response", right?
    It is the same.

    If it is MVC, requests should be distributed by some kind of routing.
    Prepare a controller to receive requests from Ajax and return the response in the view.
    However, the view is not normal HTML, but just a string, for example. Most of them are in JSON format.

    In this case, a request to send "Title"
    Receive the result, search something on the server side, and create a "response" that returns the result.

    When you receive a "response", process it and reflect it in the HTML.

    The flow is roughly like this.

    I don't know if there is an Ajax article on ASP.NET MVC itself, but
    Just by matching the way to ASP.NET MVC, thinking, receiving a request → processing and returning the response does not change whatever.

      

    -Should I prepare two view files for each movie and drama

    Since the response part is dynamic only with the character string, it may be one.

      

    -How to switch the view file with jQuery = ajax (I don't know which method to use or how to specify the path)

    As already written, the request is just the value of Title, which determines the information to be acquired by the controller.
    Maybe I just don't understand the meaning of this sentence.
    It would be helpful if you could write more concretely ...