1

I am looking for a way to pass an parameter to the user control? Right now I have a big if statement and code duplication in my user control. I want to have the loop inside the view and I want to pass the current index of the loop to the user control?

// current view
Html.RenderPartial("DetailsRateForm", ViewData.Model);

// ASP.NET MVC User control

  <% else
 {%>
 <%=Html.Hidden(Resources.RSINET.RateDetailIndex, "0")%>

<table class="prettyForm">
<thead>
    <th colspan="2">Add Rate Details</th>
</thead>
<tr>
    <td>Effective Date</td>
    <td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceEffectiveDate)%>  <a href="javascript:NewCal('RateDetail[<%="0"%>].EffectiveDate','mmddyyyy')"><img src="../../Content/Images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/></a></td>
</tr>
<tr>
    <td>Expiration Date</td>
    <td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceExpirationDate)%> <a href="javascript:NewCal('RateDetail[<%="0"%>].ExpirationDate','mmddyyyy')"><img src="../../Content/Images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/></a></td>
</tr>
<tr>
    <td>Condition Type</td>
    <td><%=Html.DropDownList(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceConditionType, ViewData.Model.CondT, "Choose Option")%></td>
</tr>
<tr>
    <td>Condition Value</td><td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceConditionValue)%></td>
</tr>
<tr>
    <td>Rate</td><td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceRate)%> </td>
</tr>
<tr>
    <td>Unit</td><td><%=Html.DropDownList(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceUnit, ViewData.Model.Unit, "Choose Option")%></td>
</tr>
<tr>
    <td>Status</td>
    <td><%=Html.DropDownList(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceActiveItem, ViewData.Model.Active, "Choose Option")%></td>
</tr>

</table>

<%} %>

1 Answer 1

1

You can pass any model to your partial view. Width this line:

Html.RenderPartial("DetailsRateForm", ViewData.Model);

You pass the current model of the page to the partial view (you do not need to explicitly do that as the current model will be passed if you do not pass a model). If you want to pass anything else you just create a class for that, instantiate a object from that class, fill it with whatever data you need and pass it to the partialview. This class can contain the model of the page as well as a simple property with the index.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.