Trying to pass Model down to partial, how do I do this?

Posted by mrblah on Stack Overflow See other posts from Stack Overflow or by mrblah
Published on 2009-12-15T23:24:08Z Indexed on 2010/04/08 0:03 UTC
Read the original article Hit count: 407

Filed under:
|

My action creates a strongly typed viewdata, which is passed to my view.

In the view, I pass the Model to the render partial method.

public ActionResult Index()
{
            ViewDataForIndex vd = new ViewDataForIndex();

            vd.Users = Users.GetAll();

            return View(vd);
}


public class ViewDataForIndex: ViewData
    {
          public IList<User> Users {get;set;}

    }

now in the view:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ViewDataForIndex>" %>

<% Html.RenderPartial("~/controls/blah.ascx", ViewData.Model); %>

and in blah.ascx:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
  1. how do I access my model now?
  2. if I wanted to create a strongly typed class for my ViewUserControl, how would I do that? inherit from?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about renderpartial