0

How can i load partial view dynamically?I tried to use with querystring as below but i got error when runtime.

My code:

@Html.Partial("_Sample?id=3")
tereško
  • 56,151
  • 24
  • 92
  • 147
user2282567
  • 751
  • 1
  • 7
  • 14

1 Answers1

1

You can do something like:

@Html.Action("Sample", "Users", new { UserId = 1 })

And in your UsersController:

[ChildActionOnly]
public ActionResult Sample(int UserId) 
{
    // do stuff here
}
Dimitar Dimitrov
  • 13,563
  • 7
  • 43
  • 71
  • i want to retrieve data on database inside this partial view.Is correct way this approach? – user2282567 May 18 '13 at 14:02
  • By the way if there is any confusion between `@Html.Partial` and `@Html.Action` check out this link: http://stackoverflow.com/questions/11766554/mvc-html-partial-or-html-action – Dimitar Dimitrov May 18 '13 at 14:17