9

I have an Asp.Net 4.0 Dynamic Data website with a LINQ to SQL data context. One of the columns in the SQL Server database is NVARCHAR(MAX) and contains an XML fragment. I have mapped this to XElement in the .dbml file. I have added metadata for the class with a UIHint for the property and I have written a Custom Field template that shows the XML contents in a TreeView. Much like How to edit a SQL Server XML data field with asp.net Dynamic Data

Now I'd like to actually edit the data field. A simple text editor will do so I thought I'd copy the MultiLine_Edit field template. On the edit page it is indeed showing and I can edit the contents. But this approach turns out to be a bit too simple for when I press update, I get a red List of validation errors: The value is not valid. at the top of the page. I commented out the DynamicValidator, but now I get a ServerError instead that it cannot save my edits cause it fails at converting my edits from String to XElement.

I found an old post on the asp.net forums from someone trying to do the same thing but it does not show a solution.

So my question is: What should my XML_Edit field template look like?

4

2 回答 2

1

尝试使用XDocument可序列化的类型。

于 2013-01-26T04:17:06.370 回答
0

LINQ to SQL 和动态数据不能很好地结合在一起。

所以不要将 XML 内容映射到 XElement。而是将其映射到字符串。

您可以很好地使用自定义字段模板,但它们基于字符串。

于 2013-01-26T21:37:10.343 回答