ASP.NET MVC View User Control - how to set IDs?

前端 未结 3 503
南旧
南旧 2021-02-04 17:38

I need a dropdown list on my page that will allow a user to select their state. Since this is probably a control that will be used elsewhere, I thought it would be a good idea

3条回答
  •  自闭症患者
    2021-02-04 18:05

    Well you can pass object data to the RenderPartial method in conjunction to the User Control to render, so you could easily do the following:

    <%= Html.RenderPartial("/someDirectory/SomeControl.ascx", "MyID") %>
    

    and in the UserControl do the following:

    
    
    ....
    

    Make sure you set the Code behind for the user control to be a generic of type ComboData for this example.

提交回复
热议问题