question

mlt-9126 avatar image
0 Votes"
mlt-9126 asked AgaveJoe commented

Different views on one page

I have a site where the user enters different information to buy each product . How do I manage that the details view page is different to be one page and the displayed information is different?

Show different items in the same view. For example, when the user clicks on product one, how do I display the items related to product one, and when the user clicks on the second product, the items specific to the second product?

like this site

https://shop.mrbeam.co.uk/

dotnet-aspnet-core-mvc
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Related products is a database design. Your table structure must support related products.

A standard web application design uses an HTTP GET to fetch presentation data or a view. MVC has the concept of a route parameter which is nothing more than segment of the URL that contains data passed to the application. Design the MVC application to pass an ID that relates the products.

 /productcategory/1


In this example route parameter "1" is used to query the database tables and return all the products related to "1". Any beginning level MVC tutorial will cover route parameters and returning related records. I think you'll be interested in the official tutorials.


0 Votes 0 ·

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered

If you are just changing the data shown then the correct approach is to put that data retrieval behind an API and use your client side framework (CSF) of choice to query the API to retrieve the related data. Once the data is returned to the client again use your CSF of choice to update the UI to show the data. There is no need for any custom views. If you aren't using a CSF yet then you need to otherwise this is going to be a really poorly performing UI.

Just for demo, if you aren't using a CSF, then the equivalent would be to post back to the server, have the server retrieve all the data for the view again, including any custom data, and then return the updated view to the client for rendering.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.