How can I reuse a DropDownList in several views with .NET MVC

后端 未结 13 1079
感动是毒
感动是毒 2020-12-13 15:53

Several views from my project have the same dropdownlist...

So, in the ViewModel from that view I have :

public IEnumerable Fo         


        
13条回答
  •  [愿得一人]
    2020-12-13 16:12

    Why not use the advantages of RenderAction: @(Html.RenderAction("ControllerForCommonElements", "CommonDdl"))

    Create a controller, and an action that returns the Ddl and and just reference it in the views.

    See some tips here on how you could use it

    This way you can also cache this result. Actually the guys building StackOverflow talked about the pros of using this combined with different caching rules for different elements (i.e. if the ddl does not need to be 100% up to date you could cache it for a minute or so) in a podcast a while ago.

提交回复
热议问题