如何从textfield获取值到变量

时间:2015-02-13 03:17:24

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

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

这是我发送电子邮件的代码,我想从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);

}

1 个答案:

答案 0 :(得分:0)

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

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