如何在不重新加载页面的情况下在C#中发送电子邮件附件。 [英] How to send email attachment in C# without reloading the page.

查看:58
本文介绍了如何在不重新加载页面的情况下在C#中发送电子邮件附件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C#中发送了一个带附件的简单电子邮件,但它可以正常工作,但需要重新加载页面。如何在不重新加载页面的情况下使用附件发送电子邮件?



我尝试使用jquery从视图中调用控制器:



[$ .post(url) ,{attachment:attachment},function(data){}); ]



但是当我在控制器部件上获取文件目的地时,我遇到了URL和浏览器限制的问题。



有另外一种方法吗?没有重新加载整个页面的附件。



谢谢!



我尝试了什么:



$ .post(url,{attachment:attachment},function(data){});



这会在控制器的参数上返回null。

I have done already a simple email sending with attachment in C# and it works but it needs to reload the page. How can I do an email sending with attachment without reloading the page?

I have tried using jquery calling a controller from the view:

[$.post(url, {attachment : attachment }, function(data){}); ]

but i'm having problems with the URL and the restriction of browsers when I'm getting the file destination on the controller part.

is there another way to do this? without reloading the whole page for the attachment.

thanks!

What I have tried:

$.post(url, {attachment : attachment }, function(data){});

this returns null on the parameter of the controller.

推荐答案

.post(url,{attachment) :attachment},function(data){}); ]



但是当我在控制器部件上获取文件目的地时,我遇到了URL和浏览器限制的问题。



有另外一种方法吗?没有重新加载整个页面的附件。



谢谢!



我尝试了什么:


.post(url, {attachment : attachment }, function(data){}); ]

but i'm having problems with the URL and the restriction of browsers when I'm getting the file destination on the controller part.

is there another way to do this? without reloading the whole page for the attachment.

thanks!

What I have tried:


.post(url,{attachment:attachment},function(data){});



这会在控制器的参数上返回null。
.post(url, {attachment : attachment }, function(data){});

this returns null on the parameter of the controller.


if (attachmentFilename != null)
{
    Attachment attachment = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
    ContentDisposition disposition = attachment.ContentDisposition;
    disposition.CreationDate = File.GetCreationTime(attachmentFilename);
    disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
    disposition.ReadDate = File.GetLastAccessTime(attachmentFilename);
    disposition.FileName = Path.GetFileName(attachmentFilename);
    disposition.Size = new FileInfo(attachmentFilename).Length;
    disposition.DispositionType = DispositionTypeNames.Attachment;
    message.Attachments.Add(attachment);                
}


这篇关于如何在不重新加载页面的情况下在C#中发送电子邮件附件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆