jeudi 1 septembre 2016

Parameter name: Internal Error: The instance of the MessageContract cannot be null in

I am using a jqgrid 4.3.3. I have this code for my jqgrid below

function ExaminationDocumentGridList(ExaminationId) {
    var url1 = '../PIMSRecords/GetExamDocument?ExaminationId=' + ExaminationId;
    $("#PersonExaminationDocList").jqGrid({
        url: url1,
        datatype: 'json',
        mtype: 'POST',
        colNames: ['RowId', 'sId', 'pID', 'Document Name', 'Document No', 'Validated By', 'Validated Date', '', '', ''],
        colModel: [
              { name: 'rowId', index: 'rowId', hidden: true, width: 65 },
              { name: 'PersonExamDocId', index: 'PersonExamDocId', hidden: true, width: 20, align: 'left' },
              { name: 'ExaminationId', index: 'ExaminationId', hidden: true, width: 65 },
              { name: 'PersonExamName', index: 'PersonExamName', width: 150, align: 'left' },
              { name: 'PersonExamNo', index: 'PersonExamNo', width: 90, align: 'center' },
              { name: 'ValidatedBy', index: 'ValidatedBy', width: 150, align: 'center' },
              { name: 'ValidatedDate', index: 'ValidatedDate', sortable: false, width: 100, align: 'center' },
              { name: 'fileextension', index: 'fileextension', hidden: true, sortable: false, width: 70, align: 'center' },
              { name: 'ImageReportId', index: 'ImageReportId', hidden: true, sortable: false, width: 70, align: 'center' },
              { name: 'ImageFileName', index: 'ImageFileName', hidden: true, sortable: false, width: 70, align: 'center' }
              ],
        pager: $('#PersonExaminationDocPager'),
        rowNum: 3,
        rowList: [3, 6, 12],
        sortname: 'ValidatedDate',
        sortorder: "desc",
        viewrecords: true,
        height: '100%',
        onSelectRow: function (id) {
            var objRowData = jQuery("#PersonExaminationDocList").getRowData(id);
            var PersonExamName = objRowData.PersonExamName;
            var PersonExamNo = objRowData.PersonExamNo;
            var ValidatedBy = objRowData.ValidatedBy;
            var ValidatedDate = objRowData.ValidatedDate;

            var docid = objRowData.ImageReportId;
            var docname = objRowData.ImageFileName;
            var fileextension = objRowData.fileextension;
            $("#hidExamDocImageReportId").val(docid);
            $("#hidExamDocImageFileName").val(docname);

            $("#PersonExamName").val(PersonExamName);
            $("#PersonExamNo").val(PersonExamNo);
            $("#divSignatoryId #HRHead option:contains(" + ValidatedBy + ")").attr('selected', 'selected');
            $("#ValidatedDate").val(ValidatedDate);
            var url = '../PIMSRecords/_ExaminationDoc/' + objRowData.PersonExamDocId;
            var pId = objRowData.PersonExamDocId;
            $("#hidEntryPersonExamDocId").val(pId);

            viewpartialExamdocs(url, "partialExamDoc");
        },
        loadComplete: function () {
            /*gets the ids of grid */
            var ids = jQuery("#PersonExaminationDocList").getDataIDs();
            /*gets the number of rows of the Grid */
            var len = ids.length, newLine;
            if (len < 3) {
                /*Make a blank newlineData */
                /*Calls the function to add row data */
                AddNewRowToGridLISTOFDOCUMENT(len, '#PersonExaminationDocList');
            }
        }
    });
}

For the function

function viewpartialExamdocs(url, partialDocumentPreview) {
    $.ajax({
        type: "POST",
        url: url,
        data: {},
        success: function (response) {
            $("#" + partialDocumentPreview + "").html(response);
            var fileId = $("#hidExamDocImageReportId").val();
            var filename = $("#hidExamDocImageFileName").val();
            fileextension = filename.substr(filename.lastIndexOf('.') + 1, 4);
            if (fileextension == 'pdf') {
                $("#EmpExamimgFirstPreview").hide();
                $("#EmpExamiFrameFirstPreview").show();
                var varsrc = "../UploadDownload/_ViewPDF?&fId=" + fileId + "&filename=" + filename;
                $("#EmpExamDocFrameId").attr('src', varsrc);
                $("#ExamDocPreviewFrameId").attr('src', varsrc);
            } else {
                $("#EmpExamimgFirstPreview").show();
                $("#EmpExamiFrameFirstPreview").hide();
            }
        },
        error: function (response) {
            alert("error" + response);
        },
        datatype: "html"
    });
}

This is for my controller

[HttpPost]
    public ActionResult _ExaminationDoc(int id)
    {
        ViewData["ExaminationDoc"] = _or.GetPersonExamDoc(id);
        return PartialView("_ExaminationDoc", ViewData["ExaminationDoc"]);
    }

Here for my the data where my controller get

public PersonExaminationDocument GetPersonExamDoc(int id)
    {
        var examdoc = (from ed in db.PersonExaminationDocuments
                       where ed.PersonExamDocId == id
                    select ed).SingleOrDefault();
        return examdoc;

    }

This code is for viewing the picture

    @model PIMS.Models.PersonExaminationDocument
<center>
    <fieldset style="width: 160px; height: 250px">
        <legend style="text-align: left; font-style: normal; font-weight: bold; font-family: Arial;
            font-size: 12px;">Document Preview</legend>
        <div id="EmpExamimgFirstPreview">
            @if (Model != null)
            {
                if (Model.ImageReportId != null)
                {
                <img  alt="ExamDoc" id="ExamDocimg"  height="220px" width="150px" src="@Url.Action("Download", "UploadDownload", new { @id = Model.ImageReportId, @fname = Model.ImageFileName })" />                                                           
                }
                else
                {
                <img  alt="ExamDoc" id="ExamDocimg"  height="220px" width="150px" src="@Url.Content("~/Content/Images/document_preview.png")"/> 
                }
            }
            else
            {
                <img  alt="ExamDoc" id="ExamDocimg"  height="220px" width="150px" src="@Url.Content("~/Content/Images/document_preview.png")"/> 
            }
        </div>
        <div id="EmpExamiFrameFirstPreview" runat="server" style="display: none">
            <iframe id="EmpExamDocFrameId" style="width: 150px; height: 220px;"></iframe>
        </div>
    </fieldset>
</center>
<input id="hidImageId" type="hidden" />
<input id="hidFNameId" type="hidden" />
<input id="hidExamuploadedDoc" type="hidden" />
<input id="hidExamDocsExtensionid" type="hidden" />

This is the code to download the picture for viewing and my error

public ActionResult Download(Guid id, string fname)
    {           
        FileTransferServiceClient client = new FileTransferServiceClient();
        DownloadRequest dr = new DownloadRequest();         
        RemoteFileInfo rmi = new RemoteFileInfo();            
        Stream stream = null;

        string pId = id.ToString();
        string Userkey = "gHeOai6bFzWskyUxX2ivq4+pJ7ALwbzwF55dZvy/23BrHAfvDVj7mg";
        string PassKey = "lLAHwegN8zdS7mIZyZZj+EmzlkUXkvEYxLvgAYjuBVtU8sw6wKXy2g";          
        client.Open();          
        rmi = client.DownloadFile(ref pId, ref fname, ref PassKey, ref  Userkey);  -------- Here is where i get my error why?
        stream = rmi.FileByteStream;         
        MemoryStream writeStream = new MemoryStream();
        Int32 chunksize = 2048;         
        Byte[] buffer = new Byte[chunksize];          
        do
        {
            Int32 bytesRead = stream.Read(buffer, 0, chunksize);
            if (bytesRead == 0)
            {
                break;
            }
            writeStream.Write(buffer, 0, bytesRead);
        } while (true);
        client.Close();       
        string ext1 = Getextension(fname);
        string ext = ext1.ToLower();
        string contentType = "image/png";          
        if ((ext == "jpeg") || (ext == "png"))
        {
            contentType = "image/png";
        }
        else if ((ext == "gif"))
        {
            contentType = "image/gif";
        }
        else if (ext == "txt")
        {
            contentType = "text/html";
        }
        else if ((ext == "doc") || (ext == "docx"))
        {
            contentType = "application/msword";
        }
        else if ((ext == "ppt") || (ext == "pptx"))
        {
            contentType = "application/vnd.ms-powerpoint";
        }
        else if (ext == "pdf")
        {
            contentType = "application/pdf";
        }
        else if ((ext == "mp3"))
        {
            contentType = "audio/mpeg";
        }
        else if (ext == "mp4")
        {
            contentType = "video/mp4";
        }
        else if (ext == "flv")
        {
            contentType = "video/x-flv";
        }
        else if (ext == "wmv")
        {
            contentType = "application/x-ms-wmv";
        }
        var imageBytes = writeStream.ToArray();

        if (imageBytes == null)
        {
            return new FilePathResult("~/Content/Images/btn_mtops_pic.png", "image/png");
        }
        else
        {
            FileContentResult file = new FileContentResult(imageBytes, contentType);
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fname);
            return file;
        }
    }

And also i got this for my TFS http://ift.tt/2bGv0Pm

This is the error i get. Anyone know about this?. Please Help. Thanks.

Aucun commentaire:

Enregistrer un commentaire