asp.net How to do MVC asynchronous query _ Practical Tips

Source: Internet
Author: User

Queries are an essential part of the project, and different teams of different projects have their own simple methods. asp.net MVC has its own unique advantages, and here is a demo that combines MVC to achieve a product list.

Problem description

For some list pages, keep a consistent query code.

Solution

1, dependent documents Jquery.js, Jquery.unobtrusive-ajax.js.
2, create a partial view, Partialview main storage server sent over the data.
3, a ViewModel containing the collection data.

The partial view code is basically as follows:

How does an MVC asynchronous query asp.net?

Question Discussion

Of all the projects you've done, the entire page is divided into two parts. The above is a conditional filter, and the following is the result of the query. When I select the filter criteria, click the query, issue a POST request, and after the server responds, update the specified area information. And these, ASP.NETMVC can help us do, so we are the integration of MVC these functions can be.

1, Ajax. BeginForm

The area (Updatetargetid) that needs to be updated after the server response is supported. Similar to the AJAX control UpdatePanel in asp.net.

2. The partial view is used to display the changes in the client request.

For the query there are many ways to achieve this demo is also I do a number of interfaces before summing up, I believe there will be a better way out, I hope you share the code.

Benefits:

1, the code more concise, unified.
2, the server each send less data (for render the entire page).

Code:

@model ilist<demo.models.product>
@foreach (Demo.Models.Product item in model)
{
<li class= " SPAN3 Tile tile-double @item. Color ">
<a href=" # ">

</a><span> @item. name</span>
</li>
}

I hope this article will help you, asp.net How to do MVC asynchronous query content is introduced here. Hope you continue to pay attention to our website! Want to learn asp.net can continue to focus on this site.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.