Search code examples
asp.net-mvcviewcontrollersnested

Including multiple views in one page


I have a controller which renders a view (~/Views/Component/Create.aspx) no problem.

When this view is displayed, I would like to either:

(1) when a user clicks on a link, in a modal popup (no problem here), display a view (NOT A PARTIAL VIEW) but a complete aspx view from (~/Views/TransportType/Index.aspx)

Why? Because (~/Views/TransportType/Index.aspx) is 100% the way it should be and it has itself renders partial views from the TransportType controller. So, in one screen i give the user the ability to (Insert / Update / Edit / Delete) without going to various screens.

or

(2) within the (~/Views/Component/Create) i would settle for rendering the <%= Html.RenderAction("Index", "TransportType") %> somewhere in the page within a div that i can toggle using JavaScript. Only when i do try to use this approach I get the CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments.

Note: I can browse directly to www.MySite.com/TransportType/Index with no problem, but if i try to use the methodology described in #2 above, i get the subsequent error above.

I have tried everything. I invested my entire day into trying to figure this out. I can easily implement a quick fix, but then it would negate the whole selling point i'm convincing my company of relative to MVC and its advantages over code-behind. Please help or i may have to roll back to the ASP.NET world of code behind.

Bottom line: "Does anyone know how to render views within views? Or am i asking the question wrong.

Here's some code:


Solution

  • If you use jquery-ui you can use the dialog method.

    e.g.:

    <a href="<%=Url.Action("Index","TransportType") %>" id="transports">Types</a>
    <div id="window"></div>
    <script type="text/javascript">
    
    $(document).ready(function(){
        $("#transports").click(function(){
            $("#window").load(this.href).dialog({title:"transport list"});
            return false;
        });
    });
    </script>
    

    Edit: To use the Html.RenderAction do not put = before and puts a ; at the end as it is not returning anything: <% Html.RenderAction("Index", "TransportType"); %>