0

I am rendering a strongly typed partial view inside dynamic page. I got a method(xyz) inside controller which populates model .

How can i populate model and render this partial view

i tried this

<% Html.RenderPartial("partialviewname",xyz()); %> 

but i am getting build error saying no reference for xyz() , i added my controller class as reference and no luck

am i missing anything?

3 Answers 3

1

What is xyz()???

Anyway....in your controller add an action like this

[HttpGet] public virtual ActionResult Create() { MyModel dm = _manager.CreateMyModel(); return PartialView( "MyModelView", dm ); } 

then create a Partial View named "MyModelView" that is strongly typed to MyModel class and you've done.

If you need further help please edit your question and add some more code from your sample

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

Comments

1

You can't call methods from the controller directly in the View. I take from your question that what you need is Html.RenderAction("xyz") instead of Html.RenderPartial.

The xyz action can then recover the model, and return a PartialView (see Lorenzo's answer) that would then be rendered inside the main view.

Comments

0

Call the xyz() method before the call to RenderPartial.

<% var myController= ViewContext.Controller as YourControllerClass; var myModel = myController.xyz(); %> 

And then you can use the var myModel:

<% Html.RenderPartial("partialviewname", myModel); %> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.