Domanda

I have this following requirement. Need to display the html Body of the Mime message in IFrame

View

<iframe id="myIframe1" src="http://localhost:23245/Home/GetMimeMessageContent?FilePath=D \MimeFiles/htmlBody-small1.eml&PartName=HtmlBody" style="width:600px;height:600px;" >

Controller

public ActionResult GetMimeMessageContent(string filePath,string partName)
    {
        var mimeModel = BuildMimeModel(filePath, partName);
        MimeHeaderModel mimeHeadermodel = new MimeHeaderModel();
        mimeHeadermodel.FromAddress = mimeHeadermodel.ToAddress = mimeHeadermodel.Subject = string.Empty;
        mimeModel.MimeHeader = mimeHeadermodel;
        return View("MailDetailsView", mimeModel.MimeBody.HtmlBody);
    }

it's not showing the HtmlBody in the Iframe. But Its calling the controller. I dont know what I am missing.

È stato utile?

Soluzione

Not sure if your using jquery or not, but:

$(function() {
var $frame = $('<iframe style="width:200px; height:100px;">');
$('body').html( $frame );
setTimeout( function() {

            $.ajax(
               url="/Home/GetMimeMessageType/small1.eml/HtmlBody",
               type:'GET',
               success: function(data){
                  var doc = $frame[0].contentWindow.document;
          var $body = $('body',doc);
          $body.html(data);
               }
            );

},1 );
 });

I have not tested the above code, but this should work fine. A few things to note:

You will need to create a custom Route to map this to your controller: http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx

You will also need to change the javascript $('body').html() to be the ID of a div as a placeholder

also you will notice i have no path, if this never changes, you should add the path to your code or you can use formcollection and change the jquery ajax to a post, and set the variables and values there.

Your content will then up up in an iframe.

Forget the whole html.renderaction, this solution gives you a little more scope

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top