0

This is my first Mvc project so my apologies if i am asking something dumb. I have a DropDownList that sets the kind of item. For each kind there are a few fields that need to change according to the selected type.

How can i know if the post back was fired from the drop down list? At the controller i need to know if the method was called because the DropDownList changed, and in that case i need to change the dependent fields, or, if the user press save and i have to capture and store all data.

The best approach i found so far is to send an parameter on the post-back fired from the DropDownList. Still i need to clear the parameter after the post back and i am stuck there.

This looks a bit more complicated that it should for something i think is common, so probably Mvc should provide a better approach but i can't find one.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • ` – David Jun 21 '17 at 18:10
  • I used the approach at this post :https://stackoverflow.com/a/31060294/2700303 – MiguelSlv Jun 21 '17 at 18:21
  • Why? Take a step back here and determine specifically what you're trying to accomplish. What do you want this form to do? It sounds like you just want to update some values on the page when a ` – David Jun 21 '17 at 18:23
  • The fields i need to use depend entirely on database configurations, so i can't have a controller for each type. All the custom fields are build into a dynamic table that renders bellow the page fixed fields. – MiguelSlv Jun 21 '17 at 18:27
  • 1
    You'll need to submit a form or make an AJAX request to get back your new data. The tutorial has an example with a form submission https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-search#adding-markup-to-the-index-view-to-support-search-by-genre – Jasen Jun 21 '17 at 18:29
  • 3
    @ByteArtisan: You don't need "a controller for each type". What it sounds like you do need is a controller action for posting the selected item and getting the data associated with that item. Ideally this would be done with AJAX instead of reloading the page. – David Jun 21 '17 at 18:31
  • Yes, i think that would separate things. Edit post back method would only have to save the page. Thanks. – MiguelSlv Jun 21 '17 at 18:39

0 Answers0