I want to pass some parameters to my MVC UserControl like ShowTitle(bool) and the ViewData.Model.Row . How I define my usercontrol and pass them to it? Tanx
+1
A:
You can define your control as
public partial class MyUserControl : System.Web.Mvc.ViewUserControl<MyUserControlViewData> {
}
public class MyUserControlViewData {
public IList<MyData> MyData { get; set; }
public string SomethingElse { get; set; }
}
After that you can create an instance of MyUserControlViewData classin your controller, populate with data and pass it to the view. Is that what you're looking for?
liggett78
2008-12-19 21:07:30
Thank you. Is that the only way to do it? It seems so unintelligible.
Ata
2008-12-19 21:29:10
+4
A:
You can use the RenderAction HtmlHelper, found in the MVC futures dll available at codeplex. In your main page ... <% Html.RenderAction("actionName", "controllerName", new {showTitle=true, row=ViewData.Model.Row}); %>
You need an action method on the controller with the parameters. The action then creates a ViewData for the usercontrol. The usercontrol is returned as a view with
return View("usercontrolname", model);
The .ascx file then uses the model for just the user control. The resulting HTML is rendered into the calling page.
Matthew
2008-12-19 21:32:13
Thank you Matthew. Where I can found more document about this solution or a more complete source?
Ata
2008-12-20 09:16:42