Invalid visual variable for the max-width property of a style. In MVC asp.net

4

I have the following code:

<% For Each img In Model.listadoNoticias.Item(0).FOTO
       Dim id_LaImagen = "foto_" & img.IdFoto.ToString()
       Dim src_imagen = img.RutaFoto.Split("/")
       Dim ruta_Foto = Server.MapPath("~") & src_imagen(2) & "\" & src_imagen(3) & "\" _
       & src_imagen(4) & "\" & src_imagen(5) & "\" & src_imagen(6) & "\" & src_imagen(7)
       Dim fs As System.IO.FileStream = New System.IO.FileStream(ruta_Foto.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
       Dim LaImagen As System.Drawing.Image
       LaImagen = System.Drawing.Image.FromStream(fs)
       Dim width_original = LaImagen.Width
       Dim height_original = LaImagen.Height
       Dim proporcion = width_original / height_original
       Dim max_width = 380 * proporcion & "px"
  %>
<li>                                                                                           
    <img alt="" id="foto_<%:img.IdFoto.ToString()%>"  
    src="<%:Html.Action("FotoNoticiaString", "Noticias", New With {.id = img.IdFoto}).ToString()%>" 
    style="max-height:380px;max-width:<%:max_width%>" class="img-responsive centrado_carrusel"/>                                           
</li>

Which I show images in a Carousel Slider, in the I obtain the original dimensions to calculate its proportion, defining a fixed height, and with the proportion to obtain the maximum width or width.

The value of the width ( Dim max_width ) I store it, to assign it to the style of the image, in this case the max-width , but it tells me that the value is not valid.

I would like to know what would be the correct way to assign the value of Visual to a property of the style of the image. When it is a property that is not of the style, for example assigning it an id, class, etc. of visual, the warning does not indicate me, but in this case yes.

Here I show an image of what happens

    
asked by Danilo 10.03.2016 в 05:47
source

1 answer

2

This is just a warning because on the recommendation of W3C, the property max-width: can only contain values of:

none|longitud|porcentaje|initial|inherit

examples:

max-width:none;
max-width:150px;  medida maxima en px, cm, etc.
max-width:150%; medida maxima en porcentaje
max-width:initial;
max-width:inherit

This is no problem to prevent displaying your page correctly!

Ensure that your variable proporcion contains a correct value.

<%
...
...
...
  Dim proporcion = 2
  Dim max_width = 380 * proporcion & "px"
 %>

style="max-height:380px;max-width:<%:max_width%>" class="img-responsive centrado_carrusel"/>    
    
answered by 10.03.2016 / 17:03
source