lundi 30 novembre 2015

Razor syntax binding attributes not working after migration from MVC 3 to MVC 5

After migration from MVC 3 to MVC 5 construction of setting attributes in html elements stopped to work.

<div attr="@model.Id">...</div> //output: <div>...</div>
<div class="@model.ClassName">...</div> //output: <div>...</div>

only custom attributes that are begining with data- are working

<div data-attr="@model.Id">...</div> //output: <div data-attr="7">...</div>

the workaround is to use @Html.Raw method

<div @Html.Raw(string.Format(@"class=""{0}""",model.ClassName))>...</div> //output: <div class="className">...</div>

Any ideas what happened and how to restore previous behavior?


<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="" targetFramework="net451" />

Aucun commentaire:

Enregistrer un commentaire