tags:

views:

17

answers:

2

Hi,

I have a controller with the following actions...

public ActionResult YellowList()

public ActionResult RedList()

public ActionResult BlueList()

All these actions populate the same viewModel (ListViewModel).

How do I get them all to point to the same view (aspx)?

Thanks,

ETFairfax.

A: 

In your action use this overload of the view method:

public ActionResult YellowList()
{
    ListViewModel model = GetSomeModel();
    return View("viewName", model);
}

public ActionResult RedList()
{
    ListViewModel model = GetSomeModel();
    return View("viewName", model);
}

public ActionResult BlueList()
{
    ListViewModel model = GetSomeModel();
    return View("viewName", model);
}
Serhat Özgel
Excellent. I did try that earlier, but it didn't work. Tried again afer your suggestion, and it works this time!!! User error!!!!! Many thanks for your answer.
ETFairfax
A: 

Here is Controler:

public class ColorsController : Controller
{
    //
    // GET: /Colors/

    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Red()
    {
        ViewData["Color"] = "<span style=\"color:Red\">Red</span>";
        return View("ColorName");
    }

    public ActionResult Green()
    {
        ViewData["Color"] = "<span style=\"color:Green\">Green</span>";
        return View("ColorName");
    }
}

Here is View:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>ColorName</h2>
    <h3>You Selected: <%= ViewData["Color"] %></h3>
</asp:Content>
TheVillageIdiot