سؤال

I'm engaged in a minor skirmish with Dynamic Data. I've got a custom database image field template to allow users to upload and edit images where inserting works but updating does not. I can make update work by removing the if insert mode around where the uri is set in the following code (in DBImage_Edit.ascx.cs):

protected override void ExtractValues(IOrderedDictionary dictionary)
{
  ...
  dictionary["contenttype"] = "image/" + imgext;
  dictionary["filecontents"] = new System.Data.Linq.Binary(FileUploadEdit.FileBytes);
  if (Mode == DataBoundControlMode.Insert)
  {
    dictionary["uri"] = imgname + "_" + DateTimeOffset.Now.Ticks.ToString() + "." + imgext;
  }
  ...
}

To recap, if the uri is set to something different than the previous value in the DB when editing, the new image is uploaded successfully. If the uri is the same as the previous value in the DB, even though the filecontents and contenttype are changed, SQL Server never gets the news.

The metadata:

...
[DisplayName("Uri")]
[ScaffoldColumn(true)]
[Required]
public object uri { get; set; }

[DisplayName("Graphic")]
[ScaffoldColumn(true)]
[UIHint("DBImage")]
public object filecontents { get; set; }
...

I've also removed the UpdateCheck but that did not seem to change the behavior:

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_filecontents", DbType="VarBinary(MAX)")] //, UpdateCheck=UpdateCheck.Never
public System.Data.Linq.Binary filecontents
  {
    get
    {
...

(See commented out UpdateCheck=UpdateCheck.Never above)

Kind regards,

Jordan

هل كانت مفيدة؟

المحلول

I left it alone for a week, came back and figured it out easily.. sometimes you just need go for a walk, and not over-think these things.

The issue was caching. I changed the image handler url by adding a nocache param in the OnDataBinding:

OLD:

ImageEdit.ImageUrl = "http://localhost/WebServices.CAD/ImageHandler.ashx?uri=" + row.uri;

NEW:

ImageEdit.ImageUrl = "http://localhost/WebServices.CAD/ImageHandler.ashx?nocache=" + System.DateTime.Now.Ticks.ToString() + "&uri=" + row.uri;

Works as designed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top