How to pass some parameter to an MVC user control that is not in ViewData

I want to pass some parameters to my MVC UserControl, for example ShowTitle (bool) and ViewData.Model.Row. How do I define my user control and pass it to him? Tanx

+5
source share
2 answers

You can use the RenderAction HtmlHelper found in the futures futures MVC, available at codeplex . On the home page ...

You need an action method on the controller with parameters. Then the action creates a ViewData for the usercontrol. User control is returned as a view using

return View("usercontrolname", model);

.ascx . HTML .

+5

public partial class MyUserControl : System.Web.Mvc.ViewUserControl<MyUserControlViewData> {
}

public class MyUserControlViewData {
    public IList<MyData> MyData { get; set; }
    public string SomethingElse { get; set; }
}

MyUserControlViewData , . , ?

+1

All Articles