views:

70

answers:

2

Hi,

Im using asp.net mvc. I have a create and edit form which are very similar so im using a user control for the form. and placing that in each view.

the form is very slightly different on the edit form eg it has some extra text and a link.

how can i show/hide that based on the view im in?

A: 

If you are using WebForms style control (<asp:label>), you can create a bool property on the control and trigger the visibility of the fragment based on that property.

If you are using the MVC style control (Html.RenderPartial()), you can pass the bool value in the control model. If your control does not take currently a model, your bool value will become your model.

Franci Penov
A: 

I would either put it in the model (i.e. an "IsEditMode" or "IsAddMode" parameter) or, better yet, pass it in via the ViewData:

<%
ViewData["IsEditMode"] = true;
Html.RenderPartial("FormView", Model);
%>

Then just check for the IsEditMode value in the ViewData

Eric Petroelje