tags:

views:

332

answers:

3

I have two pages I need, and want to show for the url /index and /review. The only difference between the two pages is on the review I will have a review comment section to show and Submit button. Otherwise the two pages are identical. I thought I could create a user control for the main content.

However, if I could say under the Review action, flag to show review stuff and them return the rest of the index action.

How would you (generic you) do this?

+2  A: 
// ... Make comment section visible
return Index();
Spencer Ruport
A: 

Why don't you just always include the review comment form and use client side code to show or hide it. Considering no additional data is required for the review page beyond that of which already needed on the index a round trip to a controller is not necessary. This would allow you to delete the review action and view.

Blake Taylor
+3  A: 

Model example

public class MyModel
{
  public bool ShowCommentsSection { get; set; }

  public MyModel()
  {
  }
}

Controller actions

public ActionResult Index()
{
  MyModel myModel = new MyModel();
  return View(myModel);
}

public ActionResult Review()
{
  MyModel myModel = new MyModel();
  myModel.ShowCommentsSection = true;

  //Note that we are telling the view engine to return the Index view
  return View("Index", myModel);
}

View (somewhere inside your index.aspx probably)

<% if(Model.ShowCommentsSection) { %>
  <% Html.RenderPartial("Reviews/ReviewPartial", Model); %>
<% } %>
Dan Atkinson