views:

24

answers:

2

I have the url route working like so [domain]/Listings/Colorado the Action results signature to return the model works fine ...ActionResult GetByStateName(string stateName)..

I'd like to have the same view returned by an ActionResult GetByStateName(string stateName, string priceRange) ...overloading I guess but I can't have ambiguous action results it seems..

What I need is to return the same view but but by different action results...I think.

Is optional parameters the way to go or what might be better as Ill have up to 5 differing parameters, some empty or null be I don't want to have a View for each ActionResult...?

A: 

You just need to use the second method (GetByStateName(string stateName, string priceRange)).

If the framework don't find a value for priceRange on the Request, it will set it to null... so you just need to check if priceRange is null.

Rodrigo Waltenberg
A: 

You can use a different name for the second method, and do a

return View("GetByStateName", model);

Alternatively define only the method with 2 parameters, and explicitly handle the case where the extra parameter is null.

eglasius
Thank you both for your advice...I'm still doing something dumb though as my view doesn't show the new data provided by each action method even though when I step into it ByStateName("Arizona") returns 6 Listings and ByStateAndPrice("Arizona","0-2000000") returns 2 listings...? Which are coorect in the db but my view (the same view )doesn't change???
Bryant
Action results return same model of PaginatedList type like so... return View("ShowListings", paginatedListingsByStateName); //returns 6 ..... return View("ShowListings", paginatedListingsByStateAndPrice); //return 2 The top of the veiw if helpful is <%@ Page Language="C#" MasterPageFile="~/Views/Shared/NestedSiteMaster.master" Inherits="System.Web.Mvc.ViewPage<LOTW.Code.CustomControls.PaginatedList<LOTW.Common.Listing>>" %>
Bryant
NM...I had a piece of residual code from trying something else and forgot to delete it...Thanks I like passing to the same view the same model hydrated by various search queries...thx again
Bryant
@Bryant accept answer :)
eglasius