我使用這篇文章來創建圖像幫助程序: http://www.asp.net/mvc/tutorials/older-versions/views/using-the-tagbuilder-class-to-build-html-helpers-cs。它說它取代了時期,但沒有提到其他限制。在TagBuilder.GenerateID中使用GUID字符串
這一切工作正常,除非我嘗試使用GUID字符串作爲id。
剃刀代碼:
@Html.Image(id, ....) //passes a GUID string to helper fine
的ImageHelper是完全一樣的網頁描述:
builder.GenerateId(id);
//breakpoint after this shows the builder object
//does not create an id attribute when id is a GUID string.
//using id.ToString() doesn't work for GUIDs either
使用MergeAttributes的GUID字符串正常工作:
builder.MergeAttribute("title", id); //the GUID string is img title no problem
builder.MergeAttribute("class", id); //the GUID string is class as expected
有一些使用GUID字符串作爲ID時的限制或解決方法?
Guid不是一個字符串,它是一個結構體。嘗試Guid.ToString('N'),給你一個沒有大括號或連字符的字符串 –