UpdateModel(model,collection) error

UpdateModel(model,collection) error

Old forum URL: forums.lhotka.net/forums/t/11251.aspx


xequence posted on Friday, March 23, 2012

I am unable to update my model for some strange reason without a real exception. What I am doing is selecting an image value from a gridview type dropdownlist,

 @{

    var highlightData = SF.Library.PressRelease.digital_asset.DigitalAssetList.GetReadOnlyList();

 

    WebGrid highlightImageGrid = new WebGrid(source: highlightData, rowsPerPage: 5, canPage: true, ajaxUpdateContainerId: "HighlightImageGrid");

 

 

                        @highlightImageGrid.GetHtml(htmlAttributes: new { id = "HighlightImageGrid" },

columns: highlightImageGrid.Columns(

highlightImageGrid.Column("", "", @<text><div style="display: inline-block; float: left;">

    <input type="radio"  name="@Model.PressReleaseDigitalAsset.DigitalAssetGuid" value="@item.FK_Digital_Asset_Guid" />

    <img src="@Url.Content("~/Image/150/150/d/")@item.DigitalAssetId"  />

                        </div>

                        </text>)

    )

    )

                    }

 

The problem is when I try to bind this selected value to my child of my parent object...

[HttpPost]

        [ValidateInput(false)]

        public ActionResult Edit(FormCollection collection, PressReleaseEdit pe, int id, Guid? radioValue, Guid? highlightImage)

        {

            var model = PressReleaseEdit.AdminGetPressReleaseById(id);

            if (radioValue.HasValue)

            {

                model.PressReleaseDigitalAsset.DigitalAssetGuid = (Guid)radioValue;

                model.PressReleaseDigitalAsset.FK_PressRelease_ID = model.PressReleaseId;

            }

            else

            {

                //model.PressReleaseDigitalAsset.DigitalAssetGuid = null;

                collection["PressReleaseDigitalAsset.DigitalAssetGuid"] = radioValue.ToString();

            }

 

 

            UpdateModel(model, collection);

 

 

public readonly static PropertyInfo<SF.Library.PressRelease.digital_asset.DigitalAsset> PressReleaseDigitalAssetProperty = RegisterProperty<SF.Library.PressRelease.digital_asset.DigitalAsset>(p => p.PressReleaseDigitalAsset);

        public SF.Library.PressRelease.digital_asset.DigitalAsset PressReleaseDigitalAsset

        {

            get

            {

                if (!(FieldManager.FieldExists(PressReleaseDigitalAssetProperty)))

                    LoadProperty(PressReleaseDigitalAssetProperty, DataPortal.CreateChild<SF.Library.PressRelease.digital_asset.DigitalAsset>());

                return GetProperty(PressReleaseDigitalAssetProperty);

            }

            private set { SetProperty(PressReleaseDigitalAssetProperty, value); }

        }

 

I get this error.

The model of type 'SF.Library.PressRelease.press_release.PressReleaseEdit' could not be updated.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The model of type 'SF.Library.PressRelease.press_release.PressReleaseEdit' could not be updated.

Source Error: 

Line 59: 
Line 60: 
Line 61:             UpdateModel(model, collection);
Line 62:             LoadProperty(model, PressReleaseEdit.PressReleaseIdProperty, id);
Line 63: 

Copyright (c) Marimer LLC