Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you say your dropdowns are used in several views, do you still consider these dropdowns as part of the view that is rendering them? If so, I think using a custom HTML helper or a partial view (ascx) is appropriate. Then, like you suggest, you can populate the data for the dropdowns using a common service from your domain layer. I think that is a very reasonable approach.</p> <p>However, if you feel the dropdowns are somewhat external/unrelated to the view, then you might find that using Html.RenderAction() gives you a much cleaner result. Using Html.RenderAction(), you can output the result of an Action method directly into any other view. Therefore, you can create 1 controller with the necessary Action method(s) to populate those dropdowns. For example, let say you have a view with roughly something like:</p> <pre><code>&lt;div&gt; &lt;div id="coreView1"&gt; &lt;!-- some view code here --&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="commonDropdowns"&gt; &lt;% Html.RenderAction("Create", "Dropdown"); %&gt; &lt;/div&gt; </code></pre> <p>where <em>Create</em> is the name of your method in the <em>DropdownController</em>.</p> <p>For example:</p> <pre><code>public class DropdownController : Controller { public ViewResult Create() { // do stuff here to create the ViewResult of the common Dropdowns } } </code></pre> <p><strong>Note</strong>: Some people dislike this approach as it doesn't fit the typical MVC seperation of concerns. However, it can be a really great fit for some cases.</p> <p>Hope one of these approaches can help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload