【问题标题】:How to get value from textfield to variables如何从文本字段中获取值到变量
【发布时间】:2015-02-13 03:17:23
【问题描述】:

我在 C#.net 和 extjs 中使用 Mvc。我的问题是 如何从文本字段中获取值,然后将其设置为变量并将电子邮件发送给多个收件人。

这是我发送电子邮件的代码,我想从 Extjs 文本字段 id 中获取值并将 id 设置为发送时的变量。然后我想向多个收件人发送电子邮件。

{
    xtype: 'toolbar',
    flex: 1,
    dock: 'bottom',
    ui: 'footer',
    layout: {
        pack: 'end',
        type: 'hbox'
    },
    items: [{
        xtype: 'button',
        text: 'Send Email',
        itemId: 'sen',
        //iconCls: 'cancel'
        handler: function() {
            var rec = Ext.getCmp("activityGrid").getSelectionModel().selected()[0]

            Ext.Ajax.request({
                url: '/tblt_UAT_hr/generatePreview',
                method: 'POST',
                params: {
                    //    id: Ext.get("Uath_Id").getValue(),
                    desc: rec.get("pc_desc"),
                    uat_date: rec.get("UAT_date"),
                    pcno: rec.get("pc_no"),
                    name: rec.get("name"),
                    stkid: rec.get("Stkhid")
                },
                success: function(resp) {
                    var result = Ext.decode(resp.responseText);

                    if (result.success) {
                        Ext.Ajax.request({
                            url: '/tblt_UAT_hr/SendEmailsTo',
                            method: 'POST',
                            params: {
                                from: null,
                                to: Ext.getCmp('to').getValue(),
                                subject: Ext.getCmp('subject').getValue(),
                                body: Ext.getCmp('bod').getValue(),
                                file: result.file
                            },
                            success: function(resp) {},
                            failure: function() {}
                        });
                    } else
                        mask.hide();
                },
                failure: function() {
                    mask.hide();
                }
            });
        }
    }, {
        xtype: 'button',
        text: 'Cancel',
        itemId: 'can',
        //iconCls: 'save'
    }]
}]

public JsonResult SendEmailsTo(string from, string to, string subject, string body, string file) {
    if (file != "" && file != null) {

        MailMessage mail = new MailMessage();

        SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
        smtpServer.Credentials = new System.Net.NetworkCredential("ga.ojt.sunga@gmail.com", "1993doris");
        smtpServer.Port = 587; // Gmail works on this port

        string newfile = Server.MapPath("~/Content/pdf") + "\\" + file;

        Attachment attachment = new Attachment(newfile);

        mail.From = new MailAddress("ga.ojt.sunga@gmail.com");
        //mail.To.Add(emailAdd);

        foreach(var address in to.Split(new [] {
            ";"
        }, StringSplitOptions.RemoveEmptyEntries)) {
            mail.To.Add(address);
        }

        mail.Subject = subject;
        mail.Body = body;
        mail.Attachments.Add(attachment);
        smtpServer.EnableSsl = true;

        smtpServer.Send(e);
        // return Content("email sent", "text/plain");  
    }

    return Json(new {
        success = true, msg = "success"
    }, JsonRequestBehavior.AllowGet);

}

【问题讨论】:

    标签: javascript c# .net extjs model-view-controller


    【解决方案1】:

    使用 ComponentQuery 或其他方式找到文本字段,对其调用 getValue 并将其添加到请求调用的参数中。伪代码:

    var field = Ext.ComponentQuery.query('#fieldItemId')[0];
    params:{
        yourField:field.getValue();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      相关资源
      最近更新 更多