0

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.

2
  • 1
    What error message are you getting? Commented Aug 19, 2010 at 14:14
  • It says"ProjectTasks.ascx(14): error CS1026: ) expected". at the Html.RenderPartial call. Commented Aug 19, 2010 at 14:18

2 Answers 2

3

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.

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

Comments

1

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.

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.