MVC界面请求多次的解决问题

本文介绍了一个基于Ajax的网页应用案例,该应用能够从多种邮箱中导入联系人,并支持向这些联系人发送带有定制内容的邮件。文章详细展示了前端界面设计与后端处理流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个例子是同一界面进行2次请求。可以用Ajax回调

界面前台部分代码

 

  <form action="InviteByOtherMail.html" method="post"   >
 <div  class="divshow1" style="color:Red; font-weight:bold">目前读取邮箱通讯录支持如下邮

箱:gmail(Y)、hotmail(Y)、live(Y)、tom(Y)、yahoo(Y)(有点慢)、sina(Y)、163(Y)、sohu(Y)、

tom(Y)<br />
         读取后可以发送邮件(完善版本)</div>
    <div class="member-info">
  
       <ul>
         <li><strong>输入Email地址:</strong><%= Html.TextBoxFor(model =>

model.username, new { @class = "text_input" })%></li>
         <li><strong> 输入密码:</strong><%= Html.PasswordFor(model => model.mailpass,

new { @class = "text_input" })%></li>
         <li ><input type ="button"  value ="导入"  onclick="javascript:MailSelect('username','mailpass','nameList','1'); "

 /></li>
        <li ><strong>  全选</strong> <input type="checkbox" id="all" onclick="selectAll

(this)"/></li>
    
  <li ><strong>  好友 邮件集合: </strong> <div  id="nameList" name="nameList"></div></li>
        
   <li ><strong>  要发送邮件的好友邮箱地址:</strong> <input type="text"  id="Text1" name="nameList1"/></li>
        
        <li >  <strong> 邮件正文:</strong><%= Html.TextBoxFor(model => model.strcontent

, new { @class = "text_input" })%> </li>
      <li> <strong> 当前用户: </strong>        <%= Html.TextBoxFor(model =>

model.FullName , new { @class = "text_input" })%></li>
      <li> <input type="submit" id="btn_submit" name="btn_submit"  value="发送邀请

&raquo;"  action ="Send" />   <input name="returnbutton" type="button" value="返 回"

onclick ="window.location='EspeciallhelList.html'" class="button_input" /> </li> 
         <li>  <% =  ViewData["JSAlert"]%>      </li>
       </ul>
    </div>
</form>

2Ajax回调的代码


/*
根据密码,邮箱查联系人 (非msn账号)*/

function MailSelect(thisobj, selobj, changobj,selval){

 

    $.ajax({ type: "post",
    url: "ChangeSelectMail.html",
        dataType: "json",
        data: { "mail": $('#' + thisobj).val(), "pass": $('#' + selobj).val() },

        success: function(v_return) {

            if (v_return != null || v_return != "") {
                $('#' + changobj).html(v_return.rtn);
                setTimeout(function() { if (selval != "") $('#' + changobj).val(selval); });
            }
        }
    });
}

 

后台ctroller关键代码

     //回调通过邮箱,密码查出的联系人列表(其它邮箱)
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ChangeSelectMail()
        {
            string mails = StringHelper.GetRequest("mail");//邮箱
            string pwd= StringHelper.GetRequest("pass");//密码

            return Json(new { rtn = showiFriends(mails,pwd) });
        }

        //不同邮箱导入联系人邀请
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult InviteByOtherMail(string username, string mailpass, string strcontent, string FullName,string sendmail)
        {
            MemberInfoModel model2 =    MemberInfoModel();

            model2.mailpass = mailpass; //邮箱密码
            model2.username = username;//发送邮件的地址
            model2.strcontent = strcontent;//邮件内容
            model2.sendmail = sendmail;
            string aa = model2.FullName;//发送请求的当前用户名
            ViewData["email"] = "";
            aa = FullName;
            return View(model2);
        }

         [AcceptVerbs(HttpVerbs.Post)]
          public ActionResult InviteByOtherMail(){
            string cname = StringHelper.GetRequest("FullName");//当前用户
            string users = StringHelper.GetRequest("username");//请求的用户名
            string pass = StringHelper.GetRequest("mailpass");//请求的邮件密码
            string mailto = Request.Form.Get("nameList1"); //要发送邮件的地址
                string[] maillist = mailto.Split(';');
            for (int i = 0; i < maillist.Length; i++)
            {

                inviteFriends.SendConfirmMail(maillist[i].ToString(), titile, lr2);//发邮件
            }
                    return View();
          }


        IList<Person> list;
        //查找好友的联系人邮箱地址(不是MSN)
        public string showiFriends(string username, string password)
        {
            string str = "";
            StringBuilder sd = new StringBuilder();
            GetAddressStatus status = GetContactPerson.GetAddressByEmail(username, password, null, out list);//得到邮箱登录后的状状态,返回枚举结果
            switch (status)
            {
                case GetAddressStatus.Success:

                    if (status == GetAddressStatus.Success)
                    {
                        foreach (Person p in list)
                        {
                            sd.Append(" <table >");
                            sd.Append("<tr>");
                            sd.Append("<td>");
                            sd.Append("选择: <input type='checkbox'  onclick=  'selectMe(this)'  id='" + p.Email.ToString() + "'    value='" + p.Email.ToString() + "'  /></td>");
                            sd.Append(" <td width='20px'> <input type='textbox' id='gg'   value='" + p.Email.ToString() + "'   /></td>");
                            sd.Append("</tr>");
                            sd.Append(" </table >");
                        }
                        return sd.ToString();
                    }

                    else
                    {

                        return "";
                    }
            }

                    return sd.ToString();
            }

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值