I can make the same in Django using render_to(...) but ASP.NET.
I need to provide the different form in a single asp.net page, so I want to render custom form templates and pass it into a main page.
How to make this stuff?
I try this code
<%: Html.RenderPartial(ViewData["pd"].ToString(), ViewData)%>
and I get
'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'RenderPartial' and the best extension method overload 'System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(System.Web.Mvc.HtmlHelper, string)' has some invalid arguments
Sultan
I don’t know Django, but from your description it looks like you are talking about partial views. So you could define a partial (
~/Views/Home/Foo.ascx):and then in your main view include it:
UPDATE:
Now that you have shown your code it seems that you are using the
RenderPartialmethod. This method doesn’t return anything. It writes directly to the output. You are using it incorrectly. It should be used like this:or you could also use the Partial helper:
Now as far as passing info to this partial is concerned I would very very very strongly recommend you getting rid of any ViewData and use strongly typed views and view models. So for example you would have a strongly typed main view to this model:
and then you will be able to do this:
and then have your partial strongly typed to
SomeOtherViewModel:Or even better, use the templated helpers Html.DisplayFor and Html.EditorFor. They are the best way to include partials into an ASP.NET MVC application.