tags:

views:

130

answers:

1

I am trying to pass a string parameter to an ASCX. I want to set this to the text property of a label. In the code below it shows betwen the div tags (ignore the % signs in the html tags).

<@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" >  
<%asp:Label ID="Label2" runat="server" **Text="<%# Model %> Test"** CssClass="isslabel"><%/asp:Label>  
<%div><%: Model %><%/div>   

However in the label tag no matter what I put between the angle brackets (bit it bold) in the text tag I cannot get the parameter to appear. I have tried <%: Model %> to no avail. Is the issue that the code block is inside quotes and am I just missing some character?

+1  A: 

Why are you trying to use a web forms user control with MVC?

Assuming the model is the string you want to display and you are passing this through correctly, along the lines of

<% Html.RenderPartial("MyUserControlView", "My String To Display"); %>

In your "parent" page, you will be able to do the following in your ascx:

<%= Html.Label(Model) %>

Instead of <asp:label...

Update

If you need to specify then you have a number of options, you could wrap the Html.Label call in a div and specify the class of the div (updating your css accordingly), you could use a display template, or simply explicitly use the Html like the following:

<label for="someIdThatICouldUseAnotherHtmlExtensionMethodToGet"><%: Model %></label>

The key problem with your code (as now also pointed out in the comments by @mare) is that you are trying to use a web forms control in an MVC view.

s1mm0t
Thanks but I need to be able to specify the css class and Html.Label doesn't seem to offer that
ISS Rob
See update to see how to specify the css class
s1mm0t