views:

145

answers:

2

I am using a strongly typed user control in one of the view. The coding is as follows:

This is the call in my View:

<table>
    <%    
    for (int i = 0; i < ((List<string>)ViewData["MyProjects"]).Count; i++)
    {
        string viewIndex = "MyTasks" + i.ToString();%>
    <tr>
        <td>
            <%Html.RenderPartial("ProjectTasks", ViewData[viewIndex]); %>
        </td>
    </tr>
    <% } %>
</table>

My user control has the following code:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<Application_Service.DTOs.TaskDTO>>" %>
<%if(Model.Count > 0){ %>
<table>   
    <tr>
        <td>Task Name</td>
        <td>Task Status</td>
    </tr>
    <% foreach (var item in ViewData.Model) {%>
    <tr>
        <td>
            <%:Html.Label(item.TaskName); %>
        </td>
        <td>
            <%:Html.Label(item.TaskStatus.ToString());%>
        </td>
    </tr>
    <%} %>
</table>
<%} %>

The problem is that I get an error while trying to call bind the model in user control. I am not sure what is the problem here.

Error Message:

"ProjectTasks.ascx(14): error CS1026: ) expected". at the Html.RenderPartial call.

+1  A: 

Found the issue. html.Label should not end with ";". <%:Html.Label(item.TaskStatus.ToString());%> should be <%:Html.Label(item.TaskStatus.ToString())%> Semicolon removed.

This is basically issue with the MVC.

Chinjoo
+2  A: 

You need to get rid of the ; on the end of your <%: statements:

<td> 
    <%:Html.Label(item.TaskName) %> 
</td> 
<td> 
    <%:Html.Label(item.TaskStatus.ToString())%> 
</td> 

Edit: Also, since I noticed you posted seconds before me that you found it, this applies to whenever you use the <%: or <%= syntax and is not Html.Label specific.

Kelsey