0

I am trying to create a partial view (re-used many times) that will prompt the user for data and return that value to the parent view.

My best solution so far is to pass to the partial view the name of a hidden object (a div, for instance) in the parent view, that the partial view will then set teh value of when the user has selected or entered a value.

Is this a bad design since the partial view is now dependent on the parent (i.e. that the object exists)?

If it is bad practice, what would be a better practice for creating re-usable data prompts?

2
  • The partial views job is to pass this value to something. Rather than know exactly what this something is how about just passing the parent into the partial? That way the partial only depends on an interface and being given something to talk to. Sep 6, 2016 at 14:18
  • @CandiedOrange What would it mean to pass the parent to the partial view? There is no post-back occurring after the user selects the data that is to be passed back to the parent
    – TruthOf42
    Sep 6, 2016 at 14:27

1 Answer 1

1

There is no post-back occurring after the user selects the data that is to be passed back to the parent

Stop. Disconnect from everything server-side. You are dealing with client side functionality, and the solution to your problem will not have anything to do with C#, ASP.NET MVC, or Razor. Instead, JavaScript is what you need. It sounds like the basic user interaction is:

  1. User chooses something in a dropdown or enters something in a text field
  2. Another are of the page should change based on what the user selected or entered?

The solution will look something like this:

  1. JavaScript listens for the change event on one or more form fields
  2. When the user changes a value (selects a new item in a dropdown or types something different in a field) do something to some other, specific HTML tag elsewhere on the page

This might be a good candidate for a question on StackOverflow, but you'll need to give specifics about your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.