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

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

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


xequence posted on Friday, March 23, 2012

I am trying to update my model that has a child object. The child object value is set to null to remove the image, but I get the error stated in the subject line.

I have a gridview of inputs, that I am using to select which image to bind to my child object.

@{

    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="radioValue" value="@item.FK_Digital_Asset_Guid" />

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

                        </div>

                        </text>)

    )

    )

                    }

 

The problem, is the model does not update and gives me this error.

[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

            {

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

                model.PressReleaseDigitalAsset.DigitalAssetGuid = (Guid?)radioValue;

            }

 

 

            UpdateModel(model, collection);

 

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:  

xequence replied on Friday, March 23, 2012

Actually, the problem is if I select my input that is designed for null value, then the error comes. This input is not bound to my imagrGrid. Any suggestions?

<div id="theImageDivGrid" style="float: left; padding: 10px">

            @* testing *@

            <input type="radio"  name="radioValue" value="null" />

            @* end testing *@

                @{

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

 

    WebGrid imageGrid = new WebGrid(source: data, rowsPerPage: 5, canPage: true, ajaxUpdateContainerId: "theImageDivGrid");

                    <table>

                        @*<tr>

                            <td>

                                <input type="radio" id="null" name="radioValue" value="0" />

                                <div>

                                    No Image</div>

                            </td>

                        </tr>*@

                        <tr>

                            <td>

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

    columns: imageGrid.Columns(

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

        <input type="radio" id="@item.DigitalAssetId" name="radioValue" value="@item.FK_Digital_Asset_Guid" />

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

    </div>

                                </text>)

    )

    )

Copyright (c) Marimer LLC