1

In my View I have:

<% 
   foreach (Personas p in Model.Personas) {
       if (p.DisType == DisType.TextArea) {
 %>

<% Html.RenderPartial("~/Views/Shared/Controls/Custom/xxx/Textbox.ascx", p); %>

<%
       }
   }
 %>

First I'm not sure that I have the <% %> right.

Second, in my Partial View Textbox.ascx, I strongly typed it also to my ViewModel class just like I did in my View..the same ViewModel class. My ViewModel class has a Property of type Personas. So I assumed that since I'm passing a p (of type Personas) to my RenderPartial as the object to pass to it, that as long as I have strongly typed my Partial View and that object (which is the ViewModel clas) has that type in it (personas) that I can just do this now in my Partial View:

<fieldset>
    <div>
        <span>*</span><label><%=Model.Personas.Name %></label>
        <p><%=Model.Personas.Info %></p>
    </div>
    <div>
        <%=Html.TextBox(Model.Personas.Name, "",
                 new { name=Model.Personas.Name, id= Model.Personas.Id,
                       size = Model.Personas.Size1 })%>
    </div>
</fieldset>

Finally, so I tried all this. But nothing gets rendered. I don't know why. I don't know if I just have the syntax wrong in my View or I'm not getting valid data being passed, or that in my Partial View if I'm not wiring up to the passed object correctly.

1
  • You should probably keep your questions regarding the same problem to the same thread ;) Commented Jun 24, 2009 at 4:07

2 Answers 2

1

Your assumption is incorrect. If you are passing a type of "Personas" to your partial view as it's model, then it needs to inherit System.Web.Mvc.ViewUserControl<Personas>, not the same type as the parent View. The partial view cannot just "know" that your parent view Model type has a property of type Personas and somehow map the object you pass into it to that property.

Also, since you have no literal text being rendered between your server tags, you can shorten your tags to simply:

<% 
   foreach (Personas p in Model.Personas) {
       if (p.DisType == DisType.TextArea) {

         Html.RenderPartial("~/Views/Shared/Controls/Custom/xxx/Textbox", p); 

       }
   }
 %>
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks and I forgot to add .ascx to the RenderPartial tag. I changed my PartialView to expect type Personas and still, and got rid of the unneccessary <% %>, but I get no rendering of anything.
What does your partial view look like? Can you just try putting "hello" or something in it without any server tags and still get nothing?
And let me ask, what if you wanted to send multiple types to your RenderView. Are you saying to now create yet another ViewModel class to handle going the other way!?!? that sounds messy to me.
The partial view code is above...but yea, I will try a simple text to see if it renders
Is there any way to debug a View during compile time?
|
1

View should inherit from ViewUserControl<Personas>

and within the wiew the model points to eact instance of personas

<span>*</span><label><%=Model.Name %></label>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.