最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to fire mailto urls from action method - Stack Overflow

programmeradmin1浏览0评论

I am a beginner in MVC. I want to develop an action method in MVC which fires Mailto:?body=body goes here.&subject=test subject and so the default mail client will automatically populate the email for the user. Right now I have List<String> which contain mailto: urls.

Please, if you have any experience or demo code it will be helpful to me. Thanks in advance.

I am a beginner in MVC. I want to develop an action method in MVC which fires Mailto:?body=body goes here.&subject=test subject and so the default mail client will automatically populate the email for the user. Right now I have List<String> which contain mailto: urls.

Please, if you have any experience or demo code it will be helpful to me. Thanks in advance.

Share Improve this question edited Sep 16, 2014 at 20:31 mhu 18.1k10 gold badges65 silver badges94 bronze badges asked Jul 3, 2013 at 10:21 SurajSuraj 3951 gold badge3 silver badges12 bronze badges 3
  • What does action method mean? Is this in a particular framework or just raw JavaScript? – Chris Calo Commented Jul 4, 2013 at 2:34
  • ASP.NET MVC applications is organized around controllers and action methods. The controller defines action methods. Controllers can include as many action methods as needed. Action methods typically have a one-to-one mapping with user interactions. Examples of user interactions include entering a URL into the browser, clicking a link, and submitting a form. Each of these user interactions causes a request to be sent to the server. In each case, the URL of the request includes information that the MVC framework uses to invoke an action method. – Suraj Commented Jul 4, 2013 at 8:36
  • 1 Consider adding the asp tag and/or mentioning this in your question. – Chris Calo Commented Jul 4, 2013 at 11:45
Add a ment  | 

2 Answers 2

Reset to default 10

try this :

window.location.href = "mailto:[email protected]";

with body

window.location.href = "mailto:[email protected]?body=yourBody";

Event with jquery

$('button').on('click', function(){
    window.location.href = "mailto:[email protected]?body=yourBody";
});

My ActionMethod

[HttpPost]
public JsonResult emailTemplate()
{
    List<String> str = new List<String>();
    str.Add("Mailto:?body=Hello1&subject=test subject1");
    str.Add("Mailto:?body=Hello2&subject=test subject2");
    return Json(str);
}

JavaScript Function in view

function SendMailClicked() {

        $.ajax({
            type: "POST",
            url: "/Home/emailTemplate",
            //data: "{'ReviewComponentIds':'1,2,3'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                jQuery.each(response, function () {

                    window.location.href = this + '\n';
                });
            },
            failure: function (errMsg) {
                alert('failure');
            }
        });

    }
发布评论

评论列表(0)

  1. 暂无评论