0

I have a table (and model) with the following properties in an asp.net MVC 4 application:

TV Table

height width depth type brand cost

When the user answes a question about the space that they have for the TV I then do an ajax call to determine which types are possible to fit into the space they have specified. Which type of TV type they want is the following question, so some options may need to be disabled. The SQL for what types fit in the space is "select distinct type from TV where height < @height and width < @width and depth < @depth". Should I: 1. create a new model that I call from the TV controller just to return the distinct types 2. add a method to the TV model that I call from the TV controller that just returns a list of string with the types that fit

1 Answers1

0

Depends on what you want to display to the user based on her selection' e. g.

  1. If you want to display TV name + its description then returning a list of TV model will make sense.

  2. If you are just going to display a list of TV names in combo box, then returning a list of string will suffice.

Calling a new action make sense in both cases IMHO.

EDIT:

For 2 - I want to return a list of string - should I create a new data model for this, or add a method in the existing TV data model that returns a list of string?

To expand on above query, since its not clear (at least I do not visualize it) from your question i will assume few things.

Case 1: You are displaying a view say "TVSelection" to the user that does not contain list of TVModels. In this view you are expecting user to enter three values i.e. Width, Height, Depth. Now when user enter these values, she can submit the form or you can fetch the TV Brand name list on Lost Focus event as well. In any case, the question would be are you updating existing view by populating the combo box or you are displaying a new view. I am assuming you are updating existing "TVSelection" view by the means of making an AJAX call. In that case you can just call a method on your controller (which displayed the "TVSelection" view) that returns a list of TV Brand names.

Case 2: You are displaying "TVSelection" view that already has a list of TVModel objects and you update it dynamically on selection of required field (filtering). In this case you can add a method in the TVModel itself to filter names only that matches the user selection.

I found these links relevant 1 & 2.

Hope that make sense.

Please add more details to your question if this does not answer your question.

Community
  • 1
  • 1
SBirthare
  • 5,117
  • 4
  • 34
  • 59
  • For 2 - I want to return a list of string - should I create a new data model for this, or add a method in the existing TV data model that returns a list of string? – Sven Erikson Sep 11 '13 at 00:21
  • @SvenErikson: I am not sure if I understand your situation completely however I updated the answer by making few assumption. Just in case it helps. – SBirthare Sep 11 '13 at 04:43