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
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
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.
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
Hi Steve
Do you want o return 2 views in one call?
/Alex
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
Steve, it's not possible to return 2 views from one action, you can make 2 actions and return 1 view from one action.
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.
is working on a reply...