locked
component returns error to save content RRS feed

  • Question

  • User1182587605 posted

    I am working on a drop down list which populates its values based on a model. I have a problem of saving new details from an API. Please look at my code and let me know what I need to do.

    Model:

    public class RegisteredDocument
    		{
    		[JsonIgnore]
    		public string AccessKey { get; set; }
    
    		public string GuID { get; set; }
    
    		public string Symbol { get; set; }
    
    		public string DisplayName { get; set; }
    
    		public string SystemName { get; set; }
    
    		public TargetObjectEnum? ContentSource { get; set; }
    
    		public List<RegisteredDocumentOption> Options { get; set; } = new List<RegisteredDocumentOption>();
    
    		public bool IsModified { get; set; }
    		}
    
    	}

    The component which has the save functionality:

    @using Tucson.Services.Common.Administration
    @using Tucson.Services.Enumeration;
    @model RegisteredDocument
    
    <div id="divRegisterDocument">
        <div class="row">
            <div class="col-md-5" style="text-align:right; margin-top:5px; margin-bottom:5px;">
                <label style="text-align:right">Identity Symbol : </label>
            </div>
            <div class="col-md-7">
                <input class="form-control" type="text" id="txtSymbol" />
            </div>
        </div>
        <div class="row">
            <div class="col-md-5" style="text-align:right; margin-top:5px; margin-bottom:5px;">
                <label style="text-align:right">Display Name : </label>
            </div>
            <div class="col-md-7">
                <input class="form-control" type="text" id="txtDisplayName" />
            </div>
        </div>
        <div class="row">
            <div class="col-md-5" style="text-align:right; margin-top:5px; margin-bottom:5px;">
                <label style="text-align:right">System Name : </label>
            </div>
            <div class="col-md-7">
                <input class="form-control" type="text" id="txtSystemName" />
            </div>
        </div>
        <div class="row">
            <div class="col-md-5" style="text-align:right; margin-top:5px; margin-bottom:5px;">
                <label style="text-align:right">Target Object : </label>
            </div>
            <div class="col-md-7">
                <select type="text" id="ddlTargetObject" class="form-control" asp-items="@Html.GetEnumSelectList<TargetObjectEnum>()" asp-for="@Model.ContentSource">
                    
                </select>
            </div>
        </div>
    </div>
    
    <div>
        <input data-dismiss="modal" class="btn btn-block SaveButton" value="Add New Document" id="btnAddRegisteredDocument" />
        <input type="submit" data-dismiss="modal" style="display:none" class="btn btn-block SaveButton" value="Save Document" id="btnSaveNewRegisteredDocument" />
    </div>
    
    <div class="alert alert-success" id="SuccessMsgDiv" style="margin-top:50px">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <p id="SuccessMsg"></p>
    </div>
    
    <div class="alert alert-danger" id="ErrorMsgDiv" style="margin-top:50px">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <p id="ErrorMsg"></p>
    </div>
    
    <script>
        $(document).ready(function () {
            $("#SuccessMsgDiv").hide();
            $("#ErrorMsgDiv").hide();
            $("#divRegisterDocument").hide();
            $("#btnSaveNewRegisteredDocument").hide();
        });
    
        $("#btnAddRegisteredDocument").on('click', function (e) {
            $("#divRegisterDocument").toggle();
            $("#btnSaveNewRegisteredDocument").toggle();
            $("#btnAddRegisteredDocument").hide();
        });
    
        $("#btnSaveNewRegisteredDocument").on('click', function (e) {
            var NewDocumentdata = {};
    
            NewDocumentdata.Symbol = $('#txtSymbol').val();
            NewDocumentdata.DisplayName = $('#txtDisplayName').val();
            NewDocumentdata.SystemName = $('#txtSystemName').val();
            NewDocumentdata.TargetObject = $('#ddlTargetObject option:selected').text();
    
            $.ajax({
                type: "POST",
                url: '/RegisteredCarriersAndDocuments/AddNewRegisteredDocument',
                data: { registeredDocument: NewDocumentdata },
                success: function (result) {
                    console.log(result);
                    if (result == "true") {
                        $("#ErrorMsgDiv").hide()
                        $("#SuccessMsgDiv").show()
                        $('#SuccessMsg').text("New registerd document added successfully")
                    }
                    else {
                        $("#SuccessMsgDiv").hide()
                        $("#ErrorMsgDiv").show()
                        $('#ErrorMsg').text(result)
                    }
                }
            })
        });
    
    </script>
    
    

    My code for API call is:

     public string AddNewRegisteredDocument(RegisteredDocument registeredDocument)
            {
                if (registeredDocument != null)
                {
                    string response = Common.Http.Post(AuthenticatedUser.AdministrationServicesHost, "SetRegisteredDocument?token=" + Token, JsonConvert.SerializeObject(registeredDocument));
                    RegistrationResponse documentresponse = JsonConvert.DeserializeObject<RegistrationResponse>(response);
                    if (!documentresponse.Success)
                    {
                        return documentresponse.DisplayMessage.ToString();
                    }
                    return "true";
                }
                else
                    return "Please enter valid details for new registered document";
            }

    The error is from response variable is:

    {"registeredCarriers":null,"registeredDocuments":null,"success":false,"errorCode":100,"displayMessage":"Property 'RegisteredDocument.ContentSource' has not been explicitly initialized","systemMessage":"Property 'RegisteredDocument.ContentSource' has not been explicitly initialized","exceptionDetail":null}

    The content of Identity Symbol, Display Name, System Name are coming fine but the other data is not coming. Please help me what to do in the component to get it working.




     

    Tuesday, December 24, 2019 11:46 AM

Answers

  • User-719153870 posted

    Hi acmedeepak,

    "systemMessage":"Property 'RegisteredDocument.ContentSource' has not been explicitly initialized"

    This error message is quite clear, you need to initialize the 'RegisteredDocument.ContentSource' property.

    NewDocumentdata.TargetObject = $('#ddlTargetObject option:selected').text();

    You initialize the TargetObject property but we can't see this property in your RegisteredDocument class, are you confusing these two properties?

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 25, 2019 1:53 AM

All replies

  • User475983607 posted

    The content of Identity Symbol, Display Name, System Name are coming fine but the other data is not coming. Please help me what to do in the component to get it working

    There's no TargetObject property in the RegisteredDocument class.  

    Tuesday, December 24, 2019 1:28 PM
  • User-719153870 posted

    Hi acmedeepak,

    "systemMessage":"Property 'RegisteredDocument.ContentSource' has not been explicitly initialized"

    This error message is quite clear, you need to initialize the 'RegisteredDocument.ContentSource' property.

    NewDocumentdata.TargetObject = $('#ddlTargetObject option:selected').text();

    You initialize the TargetObject property but we can't see this property in your RegisteredDocument class, are you confusing these two properties?

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 25, 2019 1:53 AM