Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve 140 posts 321 karma points
    Mar 01, 2018 @ 00:42
    Steve
    0

    Multiple Views for Surface Controller action - Possible?

    Hello!
    Is it possible to use mutliple partial views with a single SurfaceController action?
    I made a SurfaceController to execute an external API call to load an IEnumerable

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 01, 2018 @ 17:49
    Alex Skrypnyk
    0

    Hi Steve

    Do you want o return 2 views in one call?

    /Alex

  • Steve 140 posts 321 karma points
    Mar 06, 2018 @ 16:12
    Steve
    0

    Hi Alex,
    I was thinking about 2 similar views that use essentially the same API call to load data (in this case, a product list). It's not a lot of code but thinking about simplicity and ease of maintenance.
    I'm relatively new to writing custom controllers/views so don't know all of the conventions and structures.
    Thanks, Steve

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 06, 2018 @ 17:18
    Alex Skrypnyk
    0

    Steve, it's not possible to return 2 views from one action, you can make 2 actions and return 1 view from one action.

  • Charles R. Matvchuk 18 posts 124 karma points
    Mar 06, 2018 @ 18:09
    Charles R. Matvchuk
    0

    You can do it in multiple ways.

    The ugliest is to pass in a parameter that is typeof view, which is not good practice.

    Another way would be to have a method that hydrates the viewmodel and sends it to the view. That way you are returning the same object to multiple controller actions but maintaining it in one location, for example: (this is also how build our nTier Solutions.

    var model = someViewModel.Get();

    return View("ViewName", model);

    here the someViewModel.Get() would be a method that executes potentially a linq statement that returns the result as IQueryable, IEnumerable or List.

    Just some thoughts.

Please Sign in or register to post replies

Write your reply to:

Draft