OK, I’m pretty sure I know the answer to this but just in case.
I know I can pass in a composite class to a view / partial view. My question though is can I pass in an object without first having a model.
So something like Html.RenderPartial("MyPartialView", new { id=10, name="slappy" });
If I can, what would the partial view look like?
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<?????>" %>
and how would I access the properties?
Model.id???
EDIT
Just a follow up based on @Graphain’s solution this is in my view;
<% Html.RenderPartial("PagedList", new { id="10" } ); %>
Within my Partial View I have this;
[<%= ViewData["id"] %>] which renders [];
However this;
<%= Html.TextBox("id") %>
Gives me a textbox with the number 10 in it.
Sure.
Your partial view declaration should look like this:
And you’ll access properties like this:
You’ll be using ViewUserControl rather than ViewUserControl(Of TModel).
This means you’ll be accessing a ViewDataDictionary rather than a ViewDataDictionary(Of TModel) and will be dealing with just regular object data rather than strongly typed data (as well as string keys rather than strong-typed property names).
This link is a good intro on the differences: